HABTM 3深嵌套

时间:2012-07-26 04:05:07

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1

错误:未知属性:size_id

项目模型

has_many :sizeables
has_many :sizes, through: :sizeables, :dependent => :destroy

accepts_nested_attributes_for :sizes,  :reject_if => lambda { |a| a.values.all?(&:blank?) }, :allow_destroy => true 

尺寸模型

has_many :sizeables
has_many :items, through: :sizeables

has_one :centimeter
accepts_nested_attributes_for :centimeter,  allow_destroy: true

厘米模型

belongs_to :size

项目控制器

def new 
    @item = Item.new
    @size = @item.sizes.build
    @size.build_centimeter  
end

项目新视图

<%= f.fields_for :sizes do |s| %>
<%= s.fields_for :centimeter do |c| %>
<%= c.text_field :height %>
<% end %>
<% end %>

错误:未知属性:size_id

0 个答案:

没有答案