How do you append a filter to the very end of a filter chain from a superclass?

有些话、适合烂在心里 提交于 2019-12-07 03:43:24

Use prepend_before_filter in your controller classes instead of before_filter or append_before_filter.

Rails calls your ApplicationController first, before the local one... so you can do something like this (using your example):

In your Application controller you'll have your before_filter callback, and a corresponding method that gets called:

before_filter :authenticate


def authenticate
  # do something
end

In the controller for the resource type you're working with...

You can redefine / override authenticate

def authenticate
 # do something else
end

You can even choose NOT to use your authenticate callback for some methods

skip_before_filter :authenticate, :only => :my_method_without_auth
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!