On 1 March 2010 09:06, LeonS <leonard.stellbr...@gmail.com> wrote:
>  def update_attributes(attributes)
>    self.attributes = attributes
>    if self.changed?
>      #kickoff something....
>    end
>    save
>  end
>
> What do you think about this solution?
>

The problem with both yours and Rob's solution is that you're doing
your post-update checks in one place, when there's more than one place
those updates can happen. Your modification of Rob's suggestion is
better, because at least you're checking in the model, rather than in
the controller.

But you might be better off doing your check regardless of where the
updates have come from (either a single attribute being assigned, or a
mass allocation), so put a "before_save" filter in your model:

  before_save :check_changed
  def check_changed
    puts (changed? ? "changed" : "unchanged")
  end


Of course, this might *cause* problems for your specific requirement,
if, for instance, there's certain fields you want to ignore changes
for. But you can always expand the "check_changed" method to do more
work; check the changed_attributes hash, etc.

-- 
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