0

嗨,这很奇怪我有 3 个模型

class Deal < ActiveRecord::Base
  has_many :deal_items, :dependent => :destroy
  accepts_nested_attributes_for :deal_items 
  attr_accessible :deal_items_attributes

end
class DealItem < ActiveRecord::Base
  self.table_name = "deals_menu_items"
  has_many :swap_items, :dependent => :destroy
  belongs_to :deal
  has_many :deal_menu_prices

  has_many :menu_items, through: :deal_menu_prices
  belongs_to :item_price

  accepts_nested_attributes_for :deal_menu_prices
  attr_accessible :deal_menu_prices_attributes
end

class DealMenuPrice < ActiveRecord::Base
  belongs_to :menu_item
  belongs_to :deal_item
  belongs_to :item_price
  attr_accessible :item_price_id, :deal_item_id, :menu_item_id, :included
end

我有视图模板

<%= nested_form_for @deal do |f| %>
  <%= f.fields_for :deal_items do |d| %>
    <%= d.fields_for :deal_menu_prices do |dm| %>
       <%= dm.select :item_price_id, :options_for_select(my_options) %>
    <% end %>
  <% end %>
<% end %> #deal form end

但是在我的控制器中,我把所有东西都弄空了,例如

"deal"=>{"deal_items_attributes"=>{"0"=>{}}, "user_id"=>4}

我做错了什么,deal_items_attributes 哈希中没有 deal_menu_prices_attributes。我期待这样的事情

"deal"=>{"deal_items_attributes"=>{"0"=>{"deal_menu_prices_attributes"=>{item_price_id: 1} }}, "user_id"=>4}
4

0 回答 0