1
我呈现出一些JSON是这样的:负载关联的对象:方法
render :json => r.to_json(:methods => ['food_item','drink_item'])
两个FOOD_ITEM和drink_item有has_one
相关价格。我怎么能加载这个在json中呈现?
THX
编辑#1 这里的一些代码 - 写昨天深夜:
class MenuItem < ActiveRecord::Base
...
#price
has_one :price, :as => :pricable
accepts_nested_attributes_for :price
end
class ObjectConnection < ActiveRecord::Base
...
def food_item
MenuItem.find(food_id)
end
def drink_item
MenuItem.find(drink_id)
end
end
你能否发布你的模型代码? – 2012-03-13 08:36:58