ActionController inherit before_filter

I have something like this:

=========================================================================
class ApplicationController < ActionController::Base
def check_auth

end
end

class BaseController < ApplicationController
before_filter :check_auth, :except => [ :getSession ]

more here…

def getSession()

end
end

class UserController < BaseController
before_filter :check_auth, :except => [ :getNotifications ]

more here…

def getNotifications()
getSession()

end
end

I was expecting wrongly that if UserController#getNotifications calls
BaseController#getSession check_auth would not be called.

If I change the before_filter in my UserController to:

before_filter :check_auth, :except => [:getSession, :getNotifications]

it works as expected.

Isn’t there a way to incorporate the before_filter settings from the
parent controller say during construction of an instance of a sub class?

Thanks for any help in advance
Pete

On Monday, September 29, 2014 9:40:24 PM UTC+1, Ruby-Forum.com User
wrote:

This strikes me as odd - I wouldn’t usually call a parent controller’s
action explicitly. Either the base controller would implement some non
action methods that I’d call or I’d call the base controller
functionality
via super.

Having said that, it was my recollection that filters were handled by
Action Controller’s perform_action so I wouldn’t have expected what you
saw
either

Fred

Thanks for your feedback Fred.

I should have added that I’m using very old Ruby (1.8.7) and Rails
(2.2.2) versions.

Also, I tried to make my example as simple as possible. In reality, it
is a little more complicated.

The error is that…

…if I invoke an action on the UserController which is implemented in
its base controller, even if the base controller has a before_filter
excluding auth_check to run for that action it will still be run unless
UserController explicitly excludes the auth_check from running for the
inherited action.

I’ve been debugging this and can see that the debugger first processes
BaseController.before_filter followed by UserController.before_filter
but I don’t know how the filters are stored and chained. I think that is
where the problem is.

Pete

On Tuesday, September 30, 2014 10:23:41 PM UTC+1, Ruby-Forum.com User
wrote:

BaseController.before_filter followed by UserController.before_filter
but I don’t know how the filters are stored and chained. I think that is
where the problem is.

That makes more sense and is now sounding like something i’d expect. You
might try using skip_before_filter .

Fred