Ruby-on-rails – How to check modified value in a model’s before_save callback

ruby, ruby-on-rails, ruby-on-rails-3, ruby-on-rails-3.1

How can I read the value that a controller has set in a before_save callback?


I have a model with a url field. Before saving, I want to check if the url was changed. If so, do some stuff with both the new and old url.

Is that possible?

Best Solution

Try something like this:

before_save { |m| if m.url_changed? ... }

Also see the docs on ActiveModel::Dirty