Forum: Ruby on Rails before_filter and the application controller

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dave H. (Guest)
on 2006-05-17 01:26
(Received via mailing list)
Hi there,

I'm having a bit of an issue with my before_filter. I know that the
put in the application.rb controller are global for all the controllers.
my application filter I'd like to allow access to the RSS feed method in
'member' controller and skip the login checks that the before_filters
currently performing.

In my application my filters look like this:

class ApplicationController < ActionController::Base

  before_filter :check_authentication, :except =>
  before_filter :register_member_activity, :except =>

    def check_authentication
        unless session[:member_id]
            session[:intended_uri] = @request.request_uri
            redirect_to :controller => 'login', :action => "signin_form"


Obviously, now all my controllers and methods have to pass through this
authentication method. For accessing RSS this doesn't work too well.

Does anyone have any ideas how to allow global access, and no filtering
one method in a different controller. I just want to expose the "RSS"
in the "Member" controller. Putting a before_filter in the Member
and doing an :except => :rss doesn't do the trick

Thank you,
Dave H.
Tom D. (Guest)
on 2006-05-17 20:00
(Received via mailing list)
I have found that it is best to just put the before_filters for
authentication in each of your controllers rather than your
application controller.  Nearly all of my controllers have at least
one publicly visible method so I would end up having to customize each
of them.

However, one alternative would be to override your
check_authentication method in your other controller.  Then you could
add some test to verify the action.  Although this is probably not the
ideal solution.


On 5/16/06, Dave H. <removed_email_address@domain.invalid> wrote:
> class ApplicationController < ActionController::Base
>     end
> and doing an :except => :rss doesn't do the trick

Tom D.
Alain R. (Guest)
on 2006-05-17 20:09
(Received via mailing list)

> Does anyone have any ideas how to allow global access, and no filtering
> to one method in a different controller.

You can add guards in the filter, based on the controller and/or action

   #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

This topic is locked and can not be replied to.