2011-01-10 52 views
1

我知道這已經覆蓋了幾個時間在這裏,但我不能似乎解決了這個錯誤 -的Rails 3 - 設計套裝形式給予質量分配錯誤

警告:不能大規模指派保護屬性:new_order_attributes

這是試圖要保存的嵌套哈希 -

Parameters: {"utf8"=>"✓","authenticity_token"=>"UNKZf7zvlyReHSCbMRRl+9y+F5/2YF8Rf64Wm9O9xyo=", "user"=>{ "new_orders_attributes"=>[{"plan_id"=>"2", "price_id"=>"2222"}], "first_name"=>"Alex", "last_name"=>"Handley", "email"=>"[email protected]", "job_title"=>"Programmer", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}} 

的用戶數據被保存,但爲了不保存。

模型

用戶

devise :database_authenticatable, 
    :recoverable, :rememberable, :trackable, :validatable 

attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :location, :country, :job_title, :company, :parent_id,:first_name,:last_name,:subscription_type, 
:orders, :plan_id, :user_id, :price_id 

has_many :orders 
has_many :plans, :through => :orders 
accepts_nested_attributes_for :orders, :plans 

訂單

class Order < ActiveRecord::Base 
belongs_to :plan 
belongs_to :user 
end 

計劃

has_many :orders 
has_many :users, :through => :orders 

的Rails -v - 3.0.3

嵌套表格

<% prefix = "user[new_orders_attributes][]" %> 
    <%= fields_for prefix, @user.orders do |order_form| %> 
    <%= order_form.hidden_field :plan_id, :value => 2 %> 
    <%= order_form.hidden_field :price_id, :value => 2222 %> 
    <% end %> 

謝謝,亞歷克斯

+0

如何在視圖中顯示新訂單的嵌套表單? – 2011-01-10 12:37:49

+0

對不起,您之前沒有看到您的評論! – Alex 2011-01-10 19:05:03

回答

2

嘗試在attr_accessible語句添加orders_attributes到屬性列表。