Sha256: 66d3d2fe6b2a530ff0389f4ce24609511de08a2b1b877249315a01ec5dfcba6f
Contents?: true
Size: 1.03 KB
Versions: 2
Compression:
Stored size: 1.03 KB
Contents
module AslonSettings class Admin::Param < ActiveRecord::Base has_many :items, :class_name=>'Admin::ItemParam' accepts_nested_attributes_for :items attr_accessible :name, :pos ,:items_attributes def self.method_missing(method, *args) method_name = method.to_s super(method, *args) rescue NoMethodError if (param=self.find_by_name(method_name)) == nil && method_name !='to_ary' param=self.create!(:name=>method_name) else param end return param end def method_missing(method, *args) method_name = method.to_s super(method, *args) rescue NoMethodError if method_name =~ /=$/ puts method_name puts args.first var_name = method_name.gsub('=', '') value = args.first o= (eval "items.where(:name=>'#{var_name}')").first if o==nil o= (eval "items.create(:name=>'#{var_name}')") end o.value = value o.save #retrieve a value else (eval "items.where(:name=>'#{method_name}')").first.value end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
aslon_settings-0.0.1 | app/models/admin/param.rb |
aslon_settings-0.1.1 | app/models/admin/param.rb |