Search code examples
ruby-on-railsformsmodels

Altering multiple rows into a model with one submit


I'm trying to put together a rails site that uses a number of models. One is a model called requests that takes in a couple pieces of information associated with essentially a single purchase. The other is a model that collects a number of the requests together under one "order" id.

The problem is, I want the view associated with request to allow for multiple request entries with one submission, and I can't figure that out. As I've currently got it, someone can submit a single request for a single "cut", but I want them to enter a number of requests for a number of cuts on a single page, with a single submission.

My current _form document associated with my view is:

<%= form_for(@request) do |f*| %>

  <div class="field">
    <%= f.label :cut %><br />
    <%= f.text_field :cut %>
  </div>
   <div class="field">
    <%= f.label :lbs %><br />
    <%= f.number_field :lbs %>
  </div>
  <div class="field">
    <%= f.label :notes %><br />
    <%= f.text_field :notes %>
  </div>
  <div class="field">
    <%= f.label "Order ID" %><br />
    <%= f.number_field :order_id %>
  </div>
  <div class="field">
    <%= f.label :status %><br />
    <%= f.number_field :status %>
  </div>

  <div class="actions">
    <%= f.submit %>
  </div>

<% end %>

Any idea how I can create a form document that allows me to enter several new 'rows' of requests with one submit? Or how to ensure they all have the same order-id?

Thanks.


Solution

  • Try these screencasts from Ryanb, I think they'll get you a long way.