I have a before_save in my Message model defined like this:
class Message < ActiveRecord::Base
before_save lambda { foo(publisher); bar }
end
When I do:
my_message.update_attributes(:created_at => ...)
foo and bar are executed.
Sometimes, I would like to update message’s fields without executing foo and bar.
How could I update, for example, the created_at field (in the database) without executing foo and bar ?
In rails 3.1 you will use update_column.
Otherwise:
In general way, the most elegant way to bypass callbacks is the following:
Then, you can do:
Or, just for one record:
If you need it specifically for a
Timeattribute, thentouchwill do the trick as mentioned by @lucapette .