ask/app/models/ask_setting.rb

29 lines
978 B
Ruby
Raw Normal View History

class AskSetting
include Mongoid::Document
include Mongoid::Timestamps
after_initialize do
2020-07-04 13:36:32 +00:00
if !self.new_record?
if self.default_setting.class != Hash && self.default_setting.class != BSON::Document
self.default_setting = {}
end
if self.default_setting[:agree_show].nil?
self.default_setting[:agree_show] = true
end
if self.default_setting[:agree_usage].nil?
self.default_setting[:agree_usage] = false
end
if self.custom_fields.class != Hash && self.custom_fields.class != BSON::Document
self.custom_fields = {}
end
self.save
end
end
def custom_fields
tmp = super
tmp.select{|k,v| v['delete'] != true}
end
2020-07-04 13:36:32 +00:00
field :default_setting, type: Hash,default: {ask_category_id: true,name: true,sex: false,mail: true,phone: false,appointment: false,recaptcha: false,agree_show: true,agree_usage: false}
field :custom_fields, type: Hash,default: {}
2020-07-04 13:36:32 +00:00
field :usage_rule
end