Forum: Ruby on Rails How to apply filter on controller in module

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.
Carl Pelletier (Guest)
on 2006-12-31 01:34
(Received via mailing list)
Hi everyone, I'm new to rails.

My application has 3 modules: Admin, Xml, Flash.

I wrote a before_filter in the application.rb that check if the user is
authenticate (my own, not the plugins). Everything work right, but now
that I split my apps in 3 modules, I don't know how to apply the
security just on the Admin module.

Of course, I can add the before_filter in each controller under Admin
module, But I looking for a global way to do it. I would like to don't
have to add the filter on each new controller of the Admin module.

Is there a way of doiing this?

Thanks

P.S. Sorry for the bad english. I'm french
Philip R. (Guest)
on 2007-01-02 02:16
(Received via mailing list)
Carl Pelletier wrote:
> I wrote a before_filter in the application.rb that check if the user is
> authenticate (my own, not the plugins). Everything work right, but now
> that I split my apps in 3 modules, I don't know how to apply the
> security just on the Admin module.
>
> Of course, I can add the before_filter in each controller under Admin
> module, But I looking for a global way to do it. I would like to don't
> have to add the filter on each new controller of the Admin module.
>
> Is there a way of doiing this?

Create a base class for all your admin controllers and add your
before_filter to that. Then you can inherit from the base class to use
the authentication.

class Admin::BaseController < ApplicationController
   before_filter :do_authentication
end

class Admin::MyAdminController < Admin::BaseController
end

--
Phil Ross
http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby
This topic is locked and can not be replied to.