<%= collection_select(:category, :category_id, Category.all, :id, :category_name ,:prompt=>"category") %>
당신이 CATEGORY_ID이 볼 수있는 매개 변수에 불구하고 table.Even 거래에서 CATEGORY_ID를 삽입에 value_id를 제출 나던하지만 거래 데이터베이스에 전달되지 않습니다 code.Any 도움이 appreciated.Thank 될 것입니다 당신collection_select 데이터베이스 늘
<%= form_for @deal ,:url=>{:action =>"create"} do |c|%>
<%= c.text_field :item_name %><br/>
<%=c.fields_for :stores do |s| %>
<%=s.text_field :store_name %>
<%end%>
<%=c.fields_for :category do |d| %>
<%= collection_select(:category, :category_id, Category.all, :id, :category_name ,:prompt=>"category") %>
<%end%>
<%= c.submit "post"%>
<%end%>
로그에서 모델
class Deal < ActiveRecord::Base
belongs_to :category
accepts_nested_attributes_for :category
end
class Category < ActiveRecord::Base
has_many :deals
end
,
Parameters: {"utf8"=>"✓", "authenticity_token"=>"oO5AtFX4HUYAhcP15y/dFzn3kjVDmweykQPqgDDuupQ=", "deal"=> {"item_name"=>"grapes", "stores_attributes"=>{"0"=>{"store_name"=>"winco"}}}, "category_id"=>"2", "commit"=>"post"}
City Load (0.1ms) SELECT "cities".* FROM "cities" WHERE "cities"."id" = ? LIMIT 1 [["id", 2]]
SQL (1.5ms) INSERT INTO "deals" ("brand", "category_id", "city_id", "created_at", "item_name", "price", "size", "stars", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) [["brand", nil], ["category_id", nil], ["city_id", 2], ["created_at", Fri, 07 Oct 2011 23:16:45 UTC +00:00], ["item_name", "grapes"], ["price", nil], ["size", nil], ["stars", nil], ["updated_at", Fri, 07 Oct 2011 23:16:45 UTC +00:00]]
SQL (0.5ms) INSERT INTO "stores" ("address", "created_at", "store_name", "updated_at") VALUES (?, ?, ?, ?) [["address", nil], ["created_at", Fri, 07 Oct 2011 23:16:45 UTC +00:00], ["store_name", "winco"], ["updated_at", Fri, 07 Oct 2011 23:16:45 UTC +00:00]]
SQL (0.9ms) INSERT INTO "store_deals" ("address", "created_at", "deal_id", "store_id", "store_name", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["address", nil], ["created_at", Fri, 07 Oct 2011 23:16:45 UTC +00:00], ["deal_id", 4], ["store_id", 4], ["store_name", nil], ["updated_at", Fri, 07 Oct 2011 23:16:45 UTC +00:00]]
마침내 당신의 설명은 의미가있었습니다. 나는 정말로 들판을 가지고 있다고 생각하지 않았습니다. 감사합니다. – katie