Ho un formato nidificato (usando gemma nested_form di Ryan B) utilizzando un has_and_belongs_to_many a has_and_belongs_to_many configurazione:La creazione di un nuovo record in Rails HABTM formato nidificato
Opening has_and_belongs_to_many :contacts
Contact has_and_belongs_to_many :openings
Quando si cerca di aggiungere un nuovo contatto ad un'apertura, in questo caso ottengo:
Can't mass-assign protected attributes: new_1346666966632
per
"opening"=>{"contacts_attributes"=>{"new_1346666966632"=>{"contacts"=>{"name"=>"Test Contact",
Ho aggiunto il corrispondente "accepts_nested_attributes_for" e "attr_accessible", e sto costruendo il contatto cioè @ opening.contacts.build e @ opening.contacts.build (params [: apertura] [: contact_attributes]) nel controller.
Dove sto andando male? Sarebbe meglio usare una relazione has_many qui?
EDIT:
Vista:
<%= simple_nested_form_for @opening, :wrapper => :plain do |f| %>
<%= f.link_to_add "Add a contact", :contacts %>
<%= f.button :submit %>
<% end %>
che utilizza un parziale per generare campi per contatto nidificato:
<%= f.fields_for :contacts, @opening.contacts.build do |contact_form| %>
<%= contact_form.input :name, :label => false, :input_html => { :class => 'span6' } %>
<%= contact_form.input :company, :label => false, :input_html => { :class => 'span6' } %>
<%= contact_form.input :telephone, :label => false, :input_html => { :class => 'span6' } %>
<%= contact_form.input :email_address, :label => false, :input_html => { :class => 'spa12' } %>
<% end %>
provare aggiungere attr_accessible: contacts_attributes e controllare – Amar
dispiace, dimenticato di dire che ho già ottenuto che troppo –
Aggiungi il tuo 'codici view' anche – Samiron