我有一个在卖家字段中嵌套商店字段的表单。他们看起来像这样
= simple_form_for @seller, url: pages_path do |f|
.span3
h5.capital Personal/Contact Details
= f.input :name, label: false, placeholder: 'Full Name (Owner/Manager)'
= f.input :mobile, label: false, placeholder: 'Mobile Phone No.'
= f.input :landline, label: false, placeholder: 'Landline No. (With STD CODE)'
= f.input :email, label: false, placeholder: 'Email ID'
.span5
h5.capital Store Details
= f.simple_fields_for :store_attributes do |builder|
= builder.input :name, label: false, placeholder: 'Store Name'
= builder.input :address, label: false, placeholder: 'Full Address'
= builder.input :city, label: false, placeholder: 'City/District',
= builder.input :pincode, label: false, placeholder: 'Pincode', class: 'pincode'
= builder.input :website, label: false, placeholder: 'Website/Facebook Page'
卖家模型看起来像这样
class Seller < User
attr_accessible :landline, :mobile, :name, :store_attributes
has_one :store
accepts_nested_attributes_for :store
validates :name, presence: true
validates :mobile, presence: true
validates :landline, presence: true
end
这是我的控制器代码
def create
@seller = Seller.new(params[:seller])
@store = Store.new(params[:store])
if @seller.save & @store.save
redirect_to @seller
else
render 'home'
end
end
当我提交表单时,我收到以下错误
PagesController #create中的ActiveRecord :: UnknownAttributeError 未知属性:seller_id
请指导我如何解决这个问题,同时保持whitelist_attributes = true。
很多人。