我有一些不需要任何持久性的rails模型,但是我希望rails认为模型实际上具有属性x,y,z,所以当调用类似to_json的方法时控制器我得到他们免费。没有相应的列在db中的rails模型属性
例如,
class ModelWithoutTableColumns << ActiveRecord::Base
def x
return "Custom stuff here"
end
有一个在数据库中没有列X的表“ModelWithoutTable”(对不起,我稍微有一些混乱的名字!)
人有一个想法如何解决这一个?
http://stackoverflow.com/questions/993839/how-to-iterate-activerecord-attributes-including-attr-accessor-methods – 2013-09-19 22:52:04