Sha256: dc2c6e045053da4609907688888aa2f26c2bc3374fe3eee8adf63420b2086186
Contents?: true
Size: 943 Bytes
Versions: 4
Compression:
Stored size: 943 Bytes
Contents
# A simple class to manage menu options, usable by other classes to build their menus. # class MenuOption < ActiveRecord::Base cattr_writer :keys def self.keys @@keys || [] end validates :value, :presence => true validate { errors.add(:key, :inclusion) if key.present? && !keys.include?(key) } acts_as_list :scope => 'menu_options.key = \"#{key}\"' scope :options_for, lambda {|key| where(:key => key).order('menu_options.position ASC') } delegate :keys, :to => 'self.class' ## # A direct SQL selection of values for a given key # # MenuOption.fetch('Email') #=> ['Personal','Work'] # # === Parameters # # [key (String)] The key for the assocated menu options. # def self.fetch_values(key) connection.send(:select_values, options_for(key).select('value').order(:position).to_sql, 'Menu Option Select') end def to_s value end # For e9 admin def role; 'administrator' end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
e9_attributes-0.0.6 | app/models/menu_option.rb |
e9_attributes-0.0.5 | app/models/menu_option.rb |
e9_attributes-0.0.4 | app/models/menu_option.rb |
e9_attributes-0.0.3 | app/models/menu_option.rb |