How to WhiteList with before_filter, by removing certain controllers
I'm wondering if there is a way to whitelist controller authentication using before_filter, also excluding the ones that you may want. Something like that in application controller :
before_filter :authenticate_user!, :except_controller => :home
Is there a way to do th开发者_开发问答at without having to put a before_filter on every controller, which is kinda messy ?
Add this to your Home Controller, to skip authentication on all actions on your home controller.
skip_before_filter authenticate_user!
Put the before_filter in the application_controller. All your other controllers should extend this one (assuming a normal rails setup) and thus inherit the behavior.
Then, put the following in any controller where you want to skip the before filter:
skip_before_filter :authenticate_user!, :only => [:new, :create]
The :only option is, well, optional. Use it specify which methods skip the before filter. If you don't have the :only, then the entire controller will skip the before_filter.
精彩评论