# Input text fields in multiple records of the same model

**URL:** <https://www.ruby-forum.com/t/input-text-fields-in-multiple-records-of-the-same-model/142039>\
**Category:** Rails\
**Created:** [July 2, 2008, 8:39pm UTC](https://www.ruby-forum.com/t/input-text-fields-in-multiple-records-of-the-same-model/142039 "2008-07-02T20:39:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 2, 2008, 8:39pm UTC](https://www.ruby-forum.com/t/input-text-fields-in-multiple-records-of-the-same-model/142039/1 "2008-07-02T20:39:16Z")

</div>

I have a form where the user can view a list of line items that has  
description (read only) and quantity (input field). Can someone please  
give me pointers on how to allow users to enter the quantity for the  
line items they want and save it in the database? I also need to  
validate to make sure that they enter integers only. TIA.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 2, 2008, 9:04pm UTC](https://www.ruby-forum.com/t/input-text-fields-in-multiple-records-of-the-same-model/142039/2 "2008-07-02T21:04:33Z")

</div>

On 2 Lip, 20:38, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a form where the user can view a list of line items that has  
> description (read only) and quantity (input field). Can someone please  
> give me pointers on how to allow users to enter the quantity for the  
> line items they want and save it in the database? I also need to  
> validate to make sure that they enter integers only. TIA.

Check this tutorial:

> **[params\[:fu\] #5 ) Update multiple models in update action atomically.](http://www.stephenchu.com/2008/03/paramsfu-5-update-multiple-models-in.html)**
>
> Updating multiple models is hard? It sounds complicated, but with Rails it actually isn't, if you know how to take advantage of it. Knowing ...

(the whole series is really great).

Basically you can do something like:  
@models = Model.update([array\_of\_ids], [{:attribute =\>  
value\_for\_first\_object}, {:attribute =\> value\_for\_second\_object},…])

Then you can iterate over @models to check for errors on returned  
objects.
