Can you have multiple before filters?

Hi,

Is it possible to specify multiple before filters in a controller…
here’s the thing: only one set of filters is to use the :except option.
Something like:

before_filter :check_for_session_cookie
before_filter :validate_user :except =>[‘login’]

which I use to a) check if the user has returned to the site and has a
saved cookie holding login details b) check to see if user is logged on,
unless they are attempting to do so.

As far as I can tell the :except is applied to both my before filters.
Am I right in thinking this is because both my filters are chained, and
the :except is applied to the chain?

thanks
Lindsay

I am using two filters without any problems like so:

before_filter :auth_login
before_filter :get_group, :only => [:edit, :delete, :show]

the :auth_login is always performed. I also checked this with an
:except option on my :get_group before_filter and the auth_login still
worked.

So, I suspect the problem lies somewhere else. Your filters should be
able to specify different conditions.

Feel free to post more info if you need more help.

Good Luck,
Tom

On 5/8/06, Lindsay B. [email protected] wrote:

saved cookie holding login details b) check to see if user is logged on,
Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Tom D.

http://blog.atomgiant.com
http://gifthat.com

On 5/8/06, Lindsay B. [email protected] wrote:

before_filter :validate_user :except =>[‘login’]

Is this an email typo, or is this your actual code?

Pat M. wrote:

On 5/8/06, Lindsay B. [email protected] wrote:

before_filter :validate_user :except =>[‘login’]

Is this an email typo, or is this your actual code?

Hi Pat, yes its an email typo. Sorry about that! I’ve followed up on
what Tom has said. There is a problem with my code elsewhere in the app

  • I’ll figure that out. The before_filters are working properly, which
    is good to know.

thanks
Lindsay