这可能是我失明的情况......不知何故我无法让我的 layout_positions_attributes 到达 layout_positions
l = Layout.new
…
[17] pry(main)> l.layout_positions
=> []
[18] pry(main)> l.layout_positions_attributes=[{:name=>'xxx'}]
=> [{:name=>"xxx"}]
[19] pry(main)> l.layout_positions
=> [] # WTF!
[20] pry(main)> l.layout_positions.build({:name=>'xxx'})
=> #<LayoutPosition id: nil, name: "xxx", active: true, columns: nil, rows: nil, layout_id: nil, pos: -1>
[21] pry(main)> l.layout_positions
=> [#<LayoutPosition id: nil, name: "xxx", active: true, columns: nil, rows: nil, layout_id: nil, pos: −1>]
父类:
class Layout < ActiveRecord::Base
attr_accessible :name, :active, :layout_positions_attributes
has_many :layout_positions
accepts_nested_attributes_for :layout_positions,
:reject_if => lambda { |a| a[:content].blank? },
:allow_destroy => true
validates_presence_of :name
end
以及属性应该去哪里……</p>
class LayoutPosition < ActiveRecord::Base
attr_accessible :name, :active, :columns, :rows, :pos
belongs_to :layout
validates_presence_of :name
end