before_filter not cancelling action

后端 未结 1 2018
暗喜
暗喜 2021-02-02 05:54

I\'m having trouble getting before filters to work in a Rails app I have recently upgraded from 1.9(?) to 2.3.11. To try and debug it, I have put a before_filter in a controller

相关标签:
1条回答
  • 2021-02-02 06:30

    Nothing pays any attention to a before-filter's return value. If you want to stop processing, you have to render something from your filter or redirect to somewhere else, from the fine guide:

    If a before filter renders or redirects, the action will not run. If there are additional filters scheduled to run after that filter they are also cancelled.

    The same text appears in the 5.2.0 guide.

    This behavior does make sense, if the filter chain doesn't complete (i.e. stops filtering part way through) then you'd end up calling controller methods with things not set up the way they were expecting them to be and that would just cause pain, suffering, and confusion and that wouldn't be at all friendly or fun.

    0 讨论(0)
提交回复
热议问题