What is purpose of around_create callback in Rails Model?

前端 未结 6 1983
野的像风
野的像风 2021-02-05 15:42

when is around_create callback code executed, in what situations we should use it?

6条回答
  •  伪装坚强ぢ
    2021-02-05 15:55

    Simpler and neat explanation about around callback I found, is given below

    The around_* callback is called around the action and inside the before_* and after_* actions. For example:

    class User
      def before_save
        puts 'before save'
      end
    
      def after_save
        puts 'after_save'
      end
    
      def around_save
        puts 'in around save'
        yield # User saved
        puts 'out around save'
      end
    end
    
    User.save
      before save
      in around save
      out around save
      after_save
    => true
    

    Originally posted here

提交回复
热议问题