Sha256: dfc080e3c73e4d571fa3d61396eef39a3d4bd5dd4ca693ce251c57bbadb2aca0
Contents?: true
Size: 1.26 KB
Versions: 1
Compression:
Stored size: 1.26 KB
Contents
class ActiveadminSettings::Setting include Mongoid::Document include Mongoid::Timestamps include Mongoid::Globalize # Fields field :name translates do field :string, :default => "" fallbacks_for_empty_translations! end mount_uploader :file, ActiveadminSettings::SettingsFileUploader # Validators validates_presence_of :name validates_uniqueness_of :name validates_length_of :name, minimum: 1 # Indexes index :name rescue index name: 1 # Mongoid 3.x workaround # Instance def type (ActiveadminSettings.all_settings[name]["type"] ||= "string").to_s end def description (ActiveadminSettings.all_settings[name]["description"] ||= "").to_s end def default_value val = (ActiveadminSettings.all_settings[name]["default_value"] ||= "").to_s if type == "file" and not val.include? '//' val = ActionController::Base.helpers.asset_path(val) end val end def value val = respond_to?(type) ? send(type).to_s : send(:string).to_s val = default_value if val.empty? val.html_safe end # Class def self.initiate_setting(name) s = self.new(name: name) if s.type == "text" or s.type == "html" s.string = s.default_value end s.save s end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
activeadmin-settings-0.3.4 | app/models/activeadmin_settings/setting.rb |