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