Hi all
I have added a before_filter method in my application. Mainly most of
the controllers use that method except one controller. The whole
controller does not use this method, so I want to exclude it from the
list
I tried
before_filter :authenticate, :except => [:methods_here ]
but how can we make an except for a controller
Thanks
You can add guards in the filter, based on the controller and/or
action
names.
Example:
#in application.rb
before_filter :login_required, :except => [:welcome,:login]
def login_required
return if self.controller_name == 'test' <<----- GUARD
unless current_user
redirect_to login_invite_url
end
end
PS:
Ref link:
http://www.techlists.org/archives/programming/railslist/2006-05/msg03732.shtml
Hi
Thanks for the fast answer
in fact I find a way
there is a method called
skip_before_filter
which you add it into the controller and it will do the job
Thanks
Yeah I’m using the skip_before_filter method too,
but still, it seems it would be better if you could specify a
controller/action like your original posts suggests
before_filter :custom_filter, :except => {:controler=>:action}
that way you can include the filter on everything by applying it to the
ApplicationController, and only remove it from the few
controllers/actions that don’t need it.
On 19 Aug 2010, at 01:11, Mark Hamil wrote:
Yeah I’m using the skip_before_filter method too,
but still, it seems it would be better if you could specify a
controller/action like your original posts suggests
before_filter :custom_filter, :except => {:controler=>:action}
before_filter :filter_method, :only => :action
or
before_filter :filter_method, :except => :action
See the ‘Filter conditions’ section of
http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
Hope that helps,
Jim