这些是模型:
class Question < ActiveRecord::Base
attr_accessible :title, :description, :inquiries_attributes
has_many :replies
has_many :groups, :through => :question_groups
has_many :question_groups
has_many :inquiries
accepts_nested_attributes_for :inquiries, :allow_destroy=>true,
:reject_if=>:all_blank
belongs_to :user
belongs_to :last_user, :class_name => "User", :foreign_key => "last_user_id"
acts_as_by_user
default_scope order("created_at DESC")
acts_as_publicable
checkboxes_for :groups
end
class Inquiry < ActiveRecord::Base
attr_accessible :title, :question_id, :inquiry_type_id, :inquiry_options_attributes
belongs_to :question
belongs_to :inquiry_type
has_many :inquiry_options
accepts_nested_attributes_for :inquiry_options, :allow_destroy=>true,
:reject_if=>:all_blank
has_many :inquiry_replies
end
class InquiryOption < ActiveRecord::Base
attr_accessible :content, :inquiry_id
belongs_to :inquiry
end
这一观点是:
<%= nested_form_for [:admin, @question] do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :title %><br />
<%= f.text_field :title %>
</p>
<p>
<%= f.label :description %><br />
<%= f.text_area :description %>
</p>
<%= f.fields_for :inquiries do |inquiry_form| %>
<p>
<%= inquiry_form.label :title %><br />
<%= inquiry_form.text_area :title, :size=>"40x5" %><br />
<%= inquiry_form.label :inquiry_type %><br />
<%= collection_select(inquiry_form, :inquiry_type_id, InquiryType.all, :id, :name, options ={:prompt => "Seleziona una tipologia"}) %><br />
<%= inquiry_form.fields_for :inquiry_options do |inquiry_option_form| %>
<p>
<%= inquiry_option_form.label :content %><br />
<%= inquiry_option_form.text_area :content, :size=>"40x5" %><br />
<%= inquiry_option_form.link_to_remove "Rimuovi risposta" %>
</p>
<% end %>
<p><%= inquiry_form.link_to_add "Aggiungi risposta", :inquiry_options %></p>
<%= inquiry_form.link_to_remove "Rimuovi domanda" %>
</p>
<% end %>
<p><%= f.link_to_add "Aggiungi domanda", :inquiries %></p>
<p>
<%= f.checkboxes_for :groups %>
</p>
<p><%= f.submit %></p>
<% end %>
In the second level, if I want to add more than 1 inquiry_option, only the first is saved. I see that when I add more than 1 inquiry_option, the second inquiry_option has the same name attribute of the first inquiry_option and so only the first is saved when I submit he form. How can I solve it?