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