Module: CustomTableSettings
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/custom_table_settings.rb
Instance Method Summary collapse
- #destroy_custom_table_settings(model_class, variant = nil) ⇒ Object
- #save_custom_table_settings(model_class, variant = nil, fields: nil, sorts: nil, per_page: nil) ⇒ Object
Instance Method Details
#destroy_custom_table_settings(model_class, variant = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/concerns/custom_table_settings.rb', line 26 def destroy_custom_table_settings model_class, variant = nil return true if self.custom_table.nil? model = model_class.model_name.to_s key = model key = "#{model}-#{variant}" if !variant.nil? return true if self.custom_table[key].nil? self.custom_table.delete(key) return save # write_attribute :custom_table, (custom_table||{}).merge(ss) end |
#save_custom_table_settings(model_class, variant = nil, fields: nil, sorts: nil, per_page: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/concerns/custom_table_settings.rb', line 9 def save_custom_table_settings model_class, variant = nil, fields: nil, sorts: nil, per_page: nil model = model_class.model_name.to_s key = model key = "#{model}-#{variant}" if !variant.nil? self.custom_table = {} if self.custom_table.nil? self.custom_table[key] = {} if self.custom_table[key].nil? self.custom_table[key][:model] = model self.custom_table[key][:fields] = fields.symbolize_keys if !fields.nil? self.custom_table[key][:sorts] = sorts if !sorts.nil? self.custom_table[key][:per_page] = per_page.to_i if !per_page.nil? && [25, 50, 100].include?(per_page.to_i) return save! # write_attribute :custom_table, (custom_table||{}).merge(ss) end |