mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Merge pull request #1659 from internetee/1629-change-settings-storage-mechanism
Replace rails-settings-cached with custom approach
This commit is contained in:
commit
8da95a5e43
23 changed files with 1050 additions and 258 deletions
|
@ -3,21 +3,23 @@ module Admin
|
|||
load_and_authorize_resource
|
||||
|
||||
def index
|
||||
@settings = Setting.unscoped
|
||||
@settings = SettingEntry.unscoped
|
||||
@validation_settings = SettingEntry.with_group('domain_validation')
|
||||
@expiration_settings = SettingEntry.with_group('domain_expiration')
|
||||
@other_settings = SettingEntry.with_group('other')
|
||||
.where.not(code: 'default_language')
|
||||
@billing_settings = SettingEntry.with_group('billing')
|
||||
@contacts_settings = SettingEntry.with_group('contacts')
|
||||
end
|
||||
|
||||
def create
|
||||
@errors = Setting.params_errors(casted_settings)
|
||||
if @errors.empty?
|
||||
casted_settings.each do |k, v|
|
||||
Setting[k] = v
|
||||
end
|
||||
|
||||
update = SettingEntry.update(casted_settings.keys, casted_settings.values)
|
||||
if update
|
||||
flash[:notice] = t('.saved')
|
||||
redirect_to [:admin, :settings]
|
||||
redirect_to %i[admin settings]
|
||||
else
|
||||
flash[:alert] = @errors.values.uniq.join(", ")
|
||||
render "admin/settings/index"
|
||||
flash[:alert] = update.errors.values.uniq.join(', ')
|
||||
render 'admin/settings/index'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -27,10 +29,7 @@ module Admin
|
|||
settings = {}
|
||||
|
||||
params[:settings].each do |k, v|
|
||||
settings[k] = v
|
||||
settings[k] = v.to_i if Setting.integer_settings.include?(k.to_sym)
|
||||
settings[k] = v.to_f if Setting.float_settings.include?(k.to_sym)
|
||||
settings[k] = (v == 'true' ? true : false) if Setting.boolean_settings.include?(k.to_sym)
|
||||
settings[k] = { value: v }
|
||||
end
|
||||
|
||||
settings
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue