# Updating multiple fields

**URL:** <https://www.ruby-forum.com/t/updating-multiple-fields/91059>\
**Category:** Rails\
**Created:** [April 4, 2007, 6:54am UTC](https://www.ruby-forum.com/t/updating-multiple-fields/91059 "2007-04-04T06:54:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edgar\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a183cd/32.png) [@Edgar\_O](https://www.ruby-forum.com/u/Edgar_O)\
**Post date:** [April 4, 2007, 6:54am UTC](https://www.ruby-forum.com/t/updating-multiple-fields/91059/1 "2007-04-04T06:54:42Z")

</div>

Hello i have 5 fields from an invoice system (code,name,price,qty,total)  
i want when the user insert a code, the system automatically fill all  
the info from the DB into these columns.

any ideas pleased?

---

<div class="post-metadata">

**Author:** ![Edgar\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a183cd/32.png) [@Edgar\_O](https://www.ruby-forum.com/u/Edgar_O)\
**Post date:** [April 4, 2007, 9:27am UTC](https://www.ruby-forum.com/t/updating-multiple-fields/91059/2 "2007-04-04T09:27:48Z")

</div>

Edgar O. wrote:

> Hello i have 5 fields from an invoice system (code,name,price,qty,total)  
> i want when the user insert a code, the system automatically fill all  
> the info from the DB into these columns.
> 
> any ideas pleased?

A field observer on the code field.  
Then, in the controller, you retrieve the object from db and then update  
the page using rjs, like:

render :update do |page|  
page[‘name’].value=your\_object.name  
page[‘price’].value=your\_object.price  
…  
end

Regards  
Massimo  
[http://www.addsw.it](http://www.addsw.it)

---

<div class="post-metadata">

**Author:** ![Edgar\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a183cd/32.png) [@Edgar\_O](https://www.ruby-forum.com/u/Edgar_O)\
**Post date:** [April 4, 2007, 9:58pm UTC](https://www.ruby-forum.com/t/updating-multiple-fields/91059/3 "2007-04-04T21:58:38Z")

</div>

Now i am confused with the observer, should look like this?

:item\_codigo = field with the data i received  
:update =\> ‘articulos’ = is the div where is my field  
get\_X\_code = mehod on my controller

\<%= observe\_field(:item\_codigo,  
:frequency =\> 0.5,  
:update =\> ‘articulos’,  
:url =\> { :action =\> :get\_X\_code},  
:with =\> “‘codigo\_id=’+escape(value)”)%\>  
??

maner wrote:

> Edgar O. wrote:
> 
> > Hello i have 5 fields from an invoice system (code,name,price,qty,total)  
> > i want when the user insert a code, the system automatically fill all  
> > the info from the DB into these columns.
> > 
> > any ideas pleased?
> 
> A field observer on the code field.  
> Then, in the controller, you retrieve the object from db and then update  
> the page using rjs, like:
> 
> render :update do |page|  
> page[‘name’].value=your\_object.name  
> page[‘price’].value=your\_object.price  
> …  
> end
> 
> Regards  
> Massimo  
> [http://www.addsw.it](http://www.addsw.it)

---

<div class="post-metadata">

**Author:** ![Edgar\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a183cd/32.png) [@Edgar\_O](https://www.ruby-forum.com/u/Edgar_O)\
**Post date:** [April 4, 2007, 11:53pm UTC](https://www.ruby-forum.com/t/updating-multiple-fields/91059/4 "2007-04-04T23:53:42Z")

</div>

how can i do the observer???

And when i pass the object to the .rjs template it return [object  
object]

---

<div class="post-metadata">

**Author:** ![Edgar\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/a183cd/32.png) [@Edgar\_O](https://www.ruby-forum.com/u/Edgar_O)\
**Post date:** [April 5, 2007, 1:05pm UTC](https://www.ruby-forum.com/t/updating-multiple-fields/91059/5 "2007-04-05T13:05:41Z")

</div>

Edgar O. wrote:

> how can i do the observer???
> 
> And when i pass the object to the .rjs template it return [object  
> object]

In your view:

\<%= observe\_field(‘item\_codigo’,  
:url =\> { :action =\> :get\_X\_code},  
:with =\> “codigo\_id”) %\>

No :update option is needed, since response is RJS

In controller:  
item=Item.find\_by\_codigo\_id(params[:codigo\_id])  
render :update do |page|  
page[‘item\_name’].value=item.name  
…  
end
