Call a method in model after find in Ruby on Rails

后端 未结 4 1511
情话喂你
情话喂你 2021-01-18 09:08

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.

T

4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 09:47

    Nowadays ((26.04.2012) this is proper way (and working!) to do that:

    class SomeClass < ActiveRecord::Base
      after_find :do_something
    
      def do_something
        # code
      end
    end
    

提交回复
热议问题