Hi again -
I'm having another problem now. I'm trying to set up a nested model form
for the setup above (so on the edit tutorial screen, someone can edit
the contents of all the examples and questions at once). In tutorial.rb
I've already set up:
accepts_nested_attributes_for :sections, :allow_destroy => true
Right now, the part of the edit view that handles sections looks like
this:
<% for section in @sections %>
<% if section.sectionable_type == "Example" %>
<% f.fields_for :examples, section.sectionable do |g| %>
<p>
<%= g.label :title %><br \>
<%= g.text_field :title %>
</p>
<p>
<%= g.label :content %><br \>
<%= g.text_area :content %>
</p>
<% end %>
<% elsif section.sectionable_type == "Question" %>
<% f.fields_for :questions, section.sectionable do |g| %>
<p>
<%= g.label :title %><br \>
<%= g.text_field :title %>
</p>
<p>
<%= g.label :prompt %><br \>
<%= g.text_area :prompt %>
</p>
<p>
<%= g.label :answer %><br \>
<%= g.text_area :answer %>
</p>
<% end %>
<% end %>
<% end %>
When I try updating some fields and submitting the form, I get a
"unknown attribute: example" error, and the params hash only contains
the information for the last example and question in the list. Looking
at the html the above generates, everything looks like the following:
<label for="tutorial_examples_title">Title</label><br \>
<input id="tutorial_examples_title" name="tutorial[examples][title]"
type="text" value="Officiis Similique Doloribus" />
<label for="tutorial_examples_content">Content</label><br \>
<textarea id="tutorial_examples_content"
name="tutorial[examples][content]">Fuga tempora aperiam...</textarea>
So... I suppose I need to differentiate the input fields by the id of
the section (or id and type of the sectionable) being edited, but I'm
not sure how to do it, or why Rails isn't doing that for me. My code
looks like the example in the API one-to-many fields_for example
(http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M001573),but
the polymorphic association must be throwing me off somewhere, and I'm
not sure where.
Does anyone have any ideas?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---