Hi.
I've got a form that I'm using with polymorphic associations. It's
super basic. The form fields will be used in multiple places, but the
hidden polymorphic fields will change with each model that needs them.
Currently in views/books/new.html.erb
<% form_for(@review) do |f| %>
<b>Title</b><%= f.text_field :title %>
<b>Body</b><%= f.text_area :body %>
<%= f.hidden_field :reviewable_type, :value => 'Book' %>
<%= f.hidden_field :reviewable_id, :value => @book.id %>
<%= f.submit "Submit" %>
<% end %>
Currently in views/reviews/_form.rhtml
<% form_for(@review) do |f| %>
<b>Title</b><%= f.text_field :title %>
<b>Body</b><%= f.text_area :body %>
<%= f.submit "Update" %>
<% end %>
Is it better to just have 2 fields in a form partial in views/reviews
and then have the other required fields in the appropriate views?
If I DRY them up, they would look like this.
In views/books/new.html.erb
<% form_for(@review) do |f| %>
<%= render :partial => 'reviews/form', :locals=>{:f => f} %>
<%= f.hidden_field :reviewable_type, :value => 'Book' %>
<%= f.hidden_field :reviewable_id, :value => @book.id %>
<%= f.submit "Submit" %>
<% end %>
In views/reviews/_form.rhtml
<b>Title</b><%= f.text_field :title %>
<b>Body</b><%= f.text_area :body %>
Thanks for the great guidance!
--
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
-~----------~----~----~----~------~----~------~--~---