Ruby on rails 多态关联不保存值
我的模型:Ruby on rails 多态关联不保存值,ruby-on-rails,Ruby On Rails,我的模型: class LineItem < ActiveRecord::Base attr_accessible :itemable belongs_to :itemable, polymorphic: true belongs_to :lead belongs_to :cart end class House < ActiveRecord::Base has_many :line_items, :as => :itemable end clas
class LineItem < ActiveRecord::Base
attr_accessible :itemable
belongs_to :itemable, polymorphic: true
belongs_to :lead
belongs_to :cart
end
class House < ActiveRecord::Base
has_many :line_items, :as => :itemable
end
class Appartment < ActiveRecord::Base
has_many :line_items, :as => :itemable
end
创建新项目列表时,不保存de table line_项目中的值(itemable_id、itemable_type)。我做错了什么?谢谢..remco尝试更换:
@cart.line_items.build item: @object
致:
而是
model=“House”
和model.constantize
在我向列表中添加房子或公寓后,您可以直接编写model=House
。访客重定向到购物车…在显示模板中,我有一个包含所有项目的循环@cart.line_items。每个都做| item |但是我如何在循环中链接到相关的房子或公寓?您可以编写:链接到item.itemable
@cart.line_items.build item: @object
@cart.line_items.build itemable: @object