Allow to update SettingEntry via SettingEntry.code=

This commit is contained in:
Karl Erik Õunapuu 2020-08-11 17:09:14 +03:00
parent 75d661b614
commit 6361a6ff49

View file

@ -27,9 +27,13 @@ class SettingEntry < ApplicationRecord
def self.method_missing(method, *args) def self.method_missing(method, *args)
super(method, *args) super(method, *args)
rescue NoMethodError rescue NoMethodError
raise NoMethodError if method.to_s.include? '=' if method.to_s[-1] == "="
stg_code = method.to_s.sub("=", "")
SettingEntry.find_by!(code: method.to_s).retrieve stg_value = args[0].to_s
SettingEntry.find_by!(code: stg_code).update(value: stg_value)
else
SettingEntry.find_by!(code: method.to_s).retrieve
end
end end
# Validators # Validators