Forum: Ruby on Rails Extending before_filter scope to entire controllers?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2007-02-01 22:49
All,

I have my check_authentication and login stuff in my base
ApplicationController in application.rb (I realize that these
could/should be in another controller).  What's nice about this setup is
that I can apply authorization checking to my entire app. just by
providing a before_filter in ApplicationController.

However, now I'm writing a controller whose methods allow users to
request a login, which obviously should be not checking for
authentication.  But I can only "except" methods by name, not by
controller membership.

I got around this by overriding the check_authentication method (defined
in ApplicationController) to do nothing in this particular controller.
This works, but feels kludgy.

Has any thought been given to allowing before_filter :only and :except
arrays to accept controller names as well as individual actions.  Then I
could just "except" this controller from the before_filter and still get
the benefit of defining the before_filter only once in
ApplicationController.

Thanks,
Wes
440dd5deeb8b6d7271bcf8c0065af3a0?d=identicon&s=25 Wes Bangerter (Guest)
on 2007-02-01 23:16
(Received via mailing list)
You can skip the before_filter by adding this to your controller:

skip_before_filter :check_authentication

:only and :except work too, so you can apply it to specific actions in
that controller.

See "Filter chain skipping" here http://api.rubyonrails.com/classes/
ActionController/Filters/ClassMethods.html


On Feb 1, 3:49 pm, Wes Gamble <rails-mailing-l...@andreas-s.net>
Bb4bdf2b184027bc38d4fb529770cde5?d=identicon&s=25 Wes Gamble (weyus)
on 2007-02-01 23:49
Wes Bangerter wrote:
> You can skip the before_filter by adding this to your controller:
>
> skip_before_filter :check_authentication
>
> :only and :except work too, so you can apply it to specific actions in
> that controller.
>
> See "Filter chain skipping" here http://api.rubyonrails.com/classes/
> ActionController/Filters/ClassMethods.html
>
>
> On Feb 1, 3:49 pm, Wes Gamble <rails-mailing-l...@andreas-s.net>

Thx!  Forgot about that one.
This topic is locked and can not be replied to.