3
votes

I am trying to figure out what is the best way to go about creating a model like "Article" and another model that is a polymorphic model called "comment". The reason I want to do this is so I don't have duplicate models for comments. So at this point I have the polymorphic model up and running and working with the article model. The problem is I want everything to be on one form. The Ability to edit the article and post a comment. Any suggestions would help me out with this dilemma.

1

1 Answers

0
votes

This can be achieved using form_tag

<%= form_tag :url => , :html => {:id=> , :method => , :class => ""} do %>
  <% text_field_tag <id>, <default_value>, :name=>"article[title]" %>
  <% text_field_tag <id>, <default_value>, :name=>"article[content]" %>
  <% text_area_tag <id>, <default_value>, :name=>"comment[id]" %>
  <% text_area_tag <id>, <default_value>, :name=>"comment[id+1]" %>
  <%= submit_tag 'save' %>
<% end %>

the params will then nicely be grouped in a hash like

{'article' => {'title' => , 'content' => }, 'comment' => {'1' => , '2' =>  . . .}} 

which you can parse to update both the models.