I have the following two tables books and records fields for books table: id, name fields for records table:id, name, status I would like to insert value ''read'' to status field in records table when name matches name in books table. Tried the following but no luck. I would appreciae if someone can lead me to the right direction. def update_status @books=Book.find(:all) for book in @books Record.update_attributes (:status=>''read'',:conditions[''records.name=?'',books.name]) end end -- 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 -~----------~----~----~----~------~----~------~--~---
* Katsuo Isono <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> [2008-10-05 13:41:43 +0200]:> > I have the following two tables books and records > > fields for books table: id, name > fields for records table:id, name, status > > I would like to insert value ''read'' to status field in records table > when name matches name in books table. Tried the following but no luck. > I would appreciae if someone can lead me to the right direction. > > def update_status > @books=Book.find(:all) > > for book in @books > Record.update_attributesI think you should use ActiveRecord.update_all instead of ActiveRecord#update_attributes, which is an instance method. Jan> (:status=>''read'',:conditions[''records.name=?'',books.name]) > end > > end > -- > Posted via http://www.ruby-forum.com/. > >-- jan=callcc{|jan|jan};jan.call(jan) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I got the result with the following: def update_status @books=Book.find(:all) for book in @books Record.update_all("status=''read'' where name=''#{book.name}''") end end Many thanks FB -- 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 -~----------~----~----~----~------~----~------~--~---