On 3 March 2010 14:04, Andy Jeffries <andyjeffr...@gmail.com> wrote:
> While technically you're right

Way to get me onside ;-)

> we don't know the full facts in what he's trying to do.

Agreed - the "oh, but I didn't tell you about this condition" syndrome.

> :-)

Let's split the difference... create a method on the user model that
checks for .changed? and sends the email, but rather than using it as
an AR callback to hook *every* update, call it from those controller
methods you want to, and use the default update_attributes
elsewhere... how's that sound?

Something along the lines of:

# User model
def update_attributes_and_notify
  self.attributes = attributes
  send_email if changed?
  save
end

# Users controller
@user = User.find(params[:id])
if @user.update_attributes_and_notify(params[:user])
working
   ---------
else
----
end

# Some other controller
@user = User.find(params[:user_id])
if @user.update_attributes(params[:user])
working
   ---------
else
----
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.

Reply via email to