Multiple Before Filters

83 views
Skip to first unread message

Dan King

unread,
Jan 19, 2012, 1:23:36 PM1/19/12
to rubyonra...@googlegroups.com
I've added two before filters in one of my controllers like so:

before_filter :filter_one
before_filter :filter_two

The first filter (:filter_one) always fires, but the second filter
(:filter_two) never does. Anyone know how to make both filters always
fire?

Thanks.

-Dan

--
Posted via http://www.ruby-forum.com/.

Jordan Miller

unread,
Jan 19, 2012, 1:59:11 PM1/19/12
to rubyonra...@googlegroups.com
what version of rails are you using? on 3.1.3 all three of these fire fine for me in my application controller...

before_filter :must_login
before_filter :must_be_member
before_filter :must_be_admin


jordan

> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>

Hassan Schroeder

unread,
Jan 19, 2012, 1:57:47 PM1/19/12
to rubyonra...@googlegroups.com
On Thu, Jan 19, 2012 at 10:23 AM, Dan King <li...@ruby-forum.com> wrote:
> I've added two before filters in one of my controllers like so:
>
> before_filter :filter_one
> before_filter :filter_two
>
> The first filter (:filter_one) always fires, but the second filter
> (:filter_two) never does. Anyone know how to make both filters always
> fire?

That works fine for me, though I would probably just put both on the
same line, e.g.
before_filter :filter_one, :filter_two

Chances are your second filter is failing somehow; adding logging
statements might help track it down.

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

Mohamad El-Husseini

unread,
Jan 19, 2012, 2:01:20 PM1/19/12
to rubyonra...@googlegroups.com
Could it be that your first filter is preventing the request from reaching your second filter?
Reply all
Reply to author
Forward
0 new messages