Creating Multiple Objects in One Form

What is the proper restful way to create/update/edit multiple non-nested objects in a single one submit form?

Is this impossible since creating/updating/editing multiple objects in one form just not restful?

I’ve done this in the past with some routing workarounds like:

<%= form_tag generated_price_path(id: 1), :method => :put do %>
  <%= fields_for "daily_prices[]", daily_price do |f| %>
        <%= f.text_field :price %> 
   <% end %>
<%= submit_tag "Submit" %>

@nicolo, if you have a Railscasts Pro subscription, there’s an episode on this. The example uses checkboxes, but a lot of it is applicable to what you’re proposing:

I have basically implemented what was described in episode 165. This creates a non-restful action to do the update. My question is whether or not there exists a restful or proper way to do this? Or is the example in railscast 165, the proper way?

You could create a form object, and then delegate the fields to the proper ActiveRecord backed models.

Here is another RailsCast to look at:

1 Like

Unfortunately, I don’t have RailsCast Pro. I’m kinda getting the impression that I’ll basically should just do this the way it’s done in Railscast 165.