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?