1
votes

Im try use this form on create product:

this is into the product_form:

<%= f.fields_for :feature do |ft| %>
    <%= ft.label :name %>
    <%= ft.text_field :name %>  
    <%= ft.label :value %>
    <%= ft.text_field :value %>
<% end %>

But when try create im get this error

Can't mass-assign protected attributes: feature

Im try put this in my Product model:

 attr_accessible :code, :description, :price, :title,:image_1,:image_2,:image_3,:image_4,:image_5,:image_6,:image_7,:image_8,:features_attributes # and feature_attributes meet


  accepts_nested_attributes_for :features

but get the same error, my association is

product.rb

  has_many :features

feature.rb

  belongs_to :product

i see the nested attributes class but dont found because what the error persists:

http://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html

the error is:

Can't mass-assign protected attributes: feature

if someone can helpe im thanks very very very much.

1

1 Answers

1
votes

I think it should be:

fields_for :features

EDIT

The name of the first argument should be the name of your association (features) and then the second argument should be the instance of your object. So you have to wrap this part in a loop like this:

<% @product.features.each do |feature| %>
  <%= f.fields_for :features, feature do |ft| %>
    <%= ft.label :name %>
    <%= ft.text_field :name %>  
    <%= ft.label :value %>
    <%= ft.text_field :value %>
  <% end %>
<% end %>