Forum: Ruby on Rails Can you have multiple before filters?

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.
Ae03102311939454d2b7f1ca3139fd97?d=identicon&s=25 Lindsay Boyd (Guest)
on 2006-05-08 10:55
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
22580f640e491f0920a192610d1df393?d=identicon&s=25 Tom Davies (Guest)
on 2006-05-08 17:25
(Received via mailing list)
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 Boyd <lindsay.boyd@ntlworld.com> 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
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Tom Davies

http://blog.atomgiant.com
http://gifthat.com
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-05-08 19:55
(Received via mailing list)
On 5/8/06, Lindsay Boyd <lindsay.boyd@ntlworld.com> wrote:
> before_filter :validate_user :except =>['login']

Is this an email typo, or is this your actual code?
Ae03102311939454d2b7f1ca3139fd97?d=identicon&s=25 Lindsay Boyd (Guest)
on 2006-05-08 20:07
Pat Maddox wrote:
> On 5/8/06, Lindsay Boyd <lindsay.boyd@ntlworld.com> 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
This topic is locked and can not be replied to.