I would like to know if it is possible to call a method from a model after using find.
Something like after_save
, but after_find
.
Thank you, Gabriel.
I would like to know if it is possible to call a method from a model after using find.
Something like after_save
, but after_find
.
Thank you, Gabriel.
Interestingly enough, this will call the method twice... learned that one the hard way.
Nowadays ((26.04.2012) this is proper way (and working!) to do that:
If you need the found object in your method:
More details here: http://guides.rubyonrails.org/active_record_callbacks.html#after-initialize-and-after-find
Edit: For Rails >= 3, see the answer from @nothing-special-here
There is. Along with
after_initialize
,after_find
is a special case, though. You have to define the method,after_find :some_method
isn't enough. This should work, though:You can read more about it in the API.