2013-10-02 2 views
0

3 가지 모델이 있습니다. 견적, 품목 및 제품.중첩 된 양식 "보호 된 속성을 대량 지정할 수 없습니다"

내 견적/new.html.erb는 항목 양식을 포함하는 부분을 렌더링하도록 설정되며 해당 항목 양식에서 부분을 렌더링하여 제품을 선택합니다.

오류 : ActiveModel :: MassAssignmentSecurity :: "대량 할당 보호 할 수 없습니다 특성 : 제품"을 만들 QuotesController 번호 오류

이 Quote.rb

(I 다음에 관련이없는 물건을 편집)
class Quote < ActiveRecord::Base 
    attr_accessible :items_attributes 

    has_many :items, :dependent => :destroy 
    accepts_nested_attributes_for :items 
end 

Item.rb

class Item < ActiveRecord::Base 
    attr_accessible :price, :product_attributes 

    belongs_to :quote 
    belongs_to :product 
    accepts_nested_attributes_for :product 
end 

Product.rb

class Product < ActiveRecord::Base 
    attr_accessible :name, :item_make 

    has_many :items 
    accepts_nested_attributes_for :items 
end 

new.html.erb

<%= simple_nested_form_for @quote do |m| %> 

    <%= m.simple_fields_for :items, :html => { :multipart => true } do |quoteform| %> 
    <%= render "form", f: quoteform %> 
    <% end %> 

    <%= m.link_to_add "Add an item", :items %> 
    <%= m.button :submit %> 
<% end %> 

_form.html.erb

<%= f.simple_fields_for :products, :html => { :multipart => true } do |x| %> 
    <% render "layouts/styleselect", g: x %> 
<% end %> 

_styleselect.html.erb

<% g.hidden_field :item_make, :value => @item.make %> 
<%= g.input :name, collection: Product.where(:item_make => 1), label: false, input_html: {:id=>"sst_style"} %> 

그래서 기본적으로 중첩 된 형태 Quote- 간다 > 품목 -> 제품이지만 품목이 제품에 속하며 문제가 원인 일 수 있습니까? item_attributes 또는 products_attributes를 항목 모델과 견적 모델에 모두 추가하려고 시도했으며 제품의 accepts_nested_attributes_for와 동일하게 시도했습니다.

감사합니다. 감사드립니다.

답변

1

products을 단수로 작성해야합니다.

<%= f.simple_fields_for :product, :html => { :multipart => true } do |x| %> 
    <% render "layouts/styleselect", g: x %> 
<% end %> 

현재이 :

<%= f.simple_fields_for :products, :html => { :multipart => true } do |x| %> 
관련 문제