Peter Marks
2007-Oct-09 00:20 UTC
Simultaneously updating multiple tables with form_remote_tag
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'' %></td></tr> 3 User Name: <%= text_field ''person'', ''user_name'' %></td></tr> 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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Peter Marks
2007-Oct-09 02:01 UTC
Re: Simultaneously updating multiple tables with form_remote_tag
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]) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---