# Simultaneously updating multiple tables with form\_remote\_tag

**URL:** <https://www.ruby-forum.com/t/simultaneously-updating-multiple-tables-with-form-remote-tag/116726>\
**Category:** Rails\
**Created:** [October 9, 2007, 2:20am UTC](https://www.ruby-forum.com/t/simultaneously-updating-multiple-tables-with-form-remote-tag/116726 "2007-10-09T02:20:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [October 9, 2007, 2:20am UTC](https://www.ruby-forum.com/t/simultaneously-updating-multiple-tables-with-form-remote-tag/116726/1 "2007-10-09T02:20:06Z")

</div>

I have two tables (Person and User) that are related as follows:

1 class Person \< ActiveRecord::Base  
2  
3 def user  
4 return User.find(:first, :conditions =\> [“person\_id = ?”, self]  
5 end  
6  
7 def user\_name  
8 return self.user.name  
9 end

I wish to update them both simultaneously with form\_remote\_tag like  
this:

1 \<%= form\_remote\_tag(:url =\> {:action =\> ‘update’, :id =\> @person})%\>  
2 First Name: \<%= text\_field ‘person’, ‘first\_name’ %\>  
3 User Name: \<%= text\_field ‘person’, ‘user\_name’ %\>  
4 \<%= submit\_tag ‘Save’ %\>  
5 \<%= end\_form\_tag %\>

with this code in the controller:

1 def update  
2 @person = Person.find(params[:id])  
3 if @person.update\_attributes(params[:person])  
4 return if request.xhr?  
5 render :partial =\> ‘info’  
6 end  
7 end

I’m guessing I can accomplish this by changing something in the  
controller, but I’m stuck at the moment. Any ideas?

---

<div class="post-metadata">

**Author:** ![dracos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@dracos](https://www.ruby-forum.com/u/dracos)\
**Post date:** [October 9, 2007, 4:01am UTC](https://www.ruby-forum.com/t/simultaneously-updating-multiple-tables-with-form-remote-tag/116726/2 "2007-10-09T04:01:28Z")

</div>

this did it:

view:  
\<%= text\_field “user”, “name” %\>

controller:  
@person = Person.find(params[:id])  
@person.update\_attributes(params[:person])  
@person.user.update\_attributes(params[:user])
