On 3 March 2010 11:51, Tom Mac <li...@ruby-forum.com> wrote: > Hi Conrad > > Thanks for your reply. But this is not working for > update_attributes. What I tried is in update action > > @user = User.find(params[:id]) > if @user.update_attributes(params[:user]) > send_mail if @user.changed? #But this is always returns false Not > working > --------- > else > ---- > end >
If you look at the source code for update_attributes, you'll see it does a "save" in the method, so once it's finished, the are no changed fields (because the record has already been updated). You need a callback filter to run in your User model; and "before_save" seems sensible to me: def before_save send_mail if self.changed? end -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.