How does an around_action callback work? An explanation is needed

后端 未结 2 1009
北海茫月
北海茫月 2021-02-05 05:28

I am terribly confused about an around_action. How do they work? Can someone please provide me with an example/explanation of how they work?

This is a quote from my Agil

2条回答
  •  既然无缘
    2021-02-05 05:36

    My understanding is as below:

    begin
        # Do before action...
        logger.info 'I am the before action'
    
        # Do the action, which is passed as a block to your "around filter"
        # Note that if you were to delete this line, the action will never be called!
        yield
    
        # Do after action...
        logger.info 'I am the after action'
    ensure
        raise ActiveRecord::Rollback
    end
    

提交回复
热议问题