# multiple input record, single model (without nested model)

**URL:** <https://discuss.rubyonrails.org/t/multiple-input-record-single-model-without-nested-model/59697>\
**Category:** rubyonrails-talk\
**Created:** [July 4, 2011, 6:48am UTC](https://discuss.rubyonrails.org/t/multiple-input-record-single-model-without-nested-model/59697 "2011-07-04T06:48:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rian\_Andrea](https://avatars.discourse-cdn.com/v4/letter/r/8e7dd6/32.png) [@Rian\_Andrea](https://discuss.rubyonrails.org/u/Rian_Andrea)\
**Post date:** [July 4, 2011, 6:48am UTC](https://discuss.rubyonrails.org/t/multiple-input-record-single-model-without-nested-model/59697/1 "2011-07-04T06:48:09Z")

</div>

hello everyone, I’m new to rails i have some question thats been quite a headache to me, so here it is:

for example i have this controller & view

controller

```ruby

  class OrdersController < ApplicationController
def new
@Order = Order.new
end def create
@Order = Order.new(params[:order])
if @Order.save
flash[:notice] = "Successfully created order."
redirect_to @Order
else
render :action => 'new'
end
end

```

View

```ruby

<%= f.submit %>

my question is :
before displaying the form above, I want to have a text_field_tag that specify how many forms (roughly said, duplicate the form div) I want to generate based on count, and then insert the data to the database simultaneously,

This is similar to ryan bates railscasts but they don't meet my requirement, i want to use single model, not nested.

the idea is to speed things up, so that the user don't have to input the data only one at a time, but multiple record at single submit

how do i do that?

Any suggestions and solutions will be much appreciated

thanks before :)

```

\<% title “Menu Order” %\> \<%= form\_for @Order do |f| %\> \<%= f.error\_messages %\>

\<%= f.label :name%\>  
\<%= f.text\_field :name, %\>

\<%= f.label :menu\_order %\>  
\<%= f.text\_field :menu\_order %\>

 
```

---

<div class="post-metadata">

**Author:** ![walterdavis](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/walterdavis/32/705_2.png) [@walterdavis](https://discuss.rubyonrails.org/u/walterdavis)\
**Post date:** [July 4, 2011, 4:39pm UTC](https://discuss.rubyonrails.org/t/multiple-input-record-single-model-without-nested-model/59697/2 "2011-07-04T16:39:43Z")

</div>

> hello everyone, I'm new to rails i have some question thats been quite a headache to me, so here it is: for example i have this controller & view controller class OrdersController \< ApplicationController
> 
> &nbsp;&nbsp;def new &nbsp;&nbsp;@Order = Order.new &nbsp;&nbsp;end
> 
> &nbsp;&nbsp;def create &nbsp;&nbsp;&nbsp;&nbsp;@Order = Order.new(params[:order]) &nbsp;&nbsp;&nbsp;&nbsp;if @Order.save &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flash[:notice] = "Successfully created order." &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;redirect\_to @Order &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;render :action =\> 'new' &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end

Rails (and Ruby) expect instance variables to begin with a lower-case letter. This may be working for you anyway, but I thought I'd point out that @Order and @order \*\*mean\*\* fundamentally different things.

> View
> 
> \<% title "Menu Order" %\> \<%= form\_for @Order do |f| %\> &nbsp;&nbsp;\<%= f.error\_messages %\>
> 
> \<div id="form-order"\> &nbsp;&nbsp;\<p\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= f.label :name%\>\<br /\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= f.text\_field :name, %\> &nbsp;&nbsp;\</p\> &nbsp;&nbsp;\<p\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= f.label :menu\_order %\>\<br /\> &nbsp;&nbsp;&nbsp;&nbsp;\<%= f.text\_field :menu\_order %\> &nbsp;&nbsp;\</p\> \</div\> &nbsp;&nbsp;\<%= f.submit %\>
> 
> my question is : before displaying the form above, I want to have a text\_field\_tag that specify how many forms (roughly said, duplicate the form div) I want to generate based on count, and then insert the data to the database simultaneously, This is similar to ryan bates railscasts but they don't meet my requirement, i want to use single model, not nested. the idea is to speed things up, so that the user don't have to input the data only one at a time, but multiple record at single submit how do i do that? Any suggestions and solutions will be much appreciated thanks before 🙂

You're going to need to shift your new and create methods around to create and expect an array of orders rather than a single order. This may be very difficult, since it is essentially swimming upstream against Rails' conventions. You might get a lot more mileage out of creating a new wrapper model, like Cart, and having it accept\_nested\_attributes\_for :orders. You can follow the Railscast that way, which works most excellently. (There are a couple of books when you build it in Rails 3, mostly to do with the JavaScript stuff because you'll get double-escaped output if you follow it precisely. Remember that h is implicit in erb templates now, and you have to mark the stuff you don't want escaped with .html\_safe.)

Walter
