0
我從dealcontroller得到這個錯誤ActiveRecord::unknown attribute: store
,我很肯定與這條線有關 @[email protected](params[:deal])
這是正確的嵌套形式嗎?這就是我所擁有的。多對多關聯嵌套表格遇到問題
class dealController < ApplicationController
def create
@city = City.find(session[:city_id])
@[email protected](params[:deal])
if @deal.save
flash[:notice]="successfully created"
redirect_to @deal
else
render 'new'
end
end
end
交易模型
class Deal < ActiveRecord::Base
belongs_to :city
has_many :stores ,:through =>:store_deals
has_many :store_deals
accepts_nested_attributes_for :store_deals
end
商店模式
class Store < ActiveRecord::Base
has_many :deals ,:through =>:store_deals
has_many :store_deals
end
商店的交易模型
class StoreDeal < ActiveRecord::Base
belongs_to :store
belongs_to :deal
end
城市模型
class City < ActiveRecord::Base
has_many :deals
end
視圖
<%= form_for @deal ,:url=>{:action =>"create"} do |f|%>
<%= f.text_field :item_name %><br/>
<%=f.fields_for :store_deal do |s| %>
<%=s.text_field :store_name %>
<%end%>
<%= f.submit "post"%>
<%end%>
仍然沒有工作 – katie
對不起,不知道爲什麼。還是一樣的錯誤信息? –