Check if current route == some route

I have a before_filter in ApplicationController in which I want to check
if the current location is the same as a certain route, so that I only
redirect non-logged in visitors to the “join” page if they’re not on
that page already.

The code I came up with is a bit ugly:

redirect_to join_url unless (@logged_in or action_name == “join”)

I’m pretty sure there is some nice way of doing this, along the lines of

… current_url == join_url

but I can’t seem to find it on Google, nor does #rubyonrails know.
Anyone?

Another way to solve this would be :exclude on the filter, but can you
exclude a specific action in a specific controller, for an
ApplicationController filter?


Henrik N

“Henrik” == Henrik N writes:

Another way to solve this would be :exclude on the filter, but can you
exclude a specific action in a specific controller, for an
ApplicationController filter?

Not in the global declaration, but in the particular controller where
you want some actions non-filtered you can do something like this:

skip_before_filter :logged_in
before_filter :logged_in, :except => [:login, :register]


Calle D. [email protected]
http://www.livejournal.com/users/cdybedahl/
“Just about anything can be done if you are demented enough.”
– Christopher C. Petro, scary.devil.monastery

Calle D. wrote:

Not in the global declaration, but in the particular controller where
you want some actions non-filtered you can do something like this:

skip_before_filter :logged_in
before_filter :logged_in, :except => [:login, :register]

I suppose that would work. Thanks!


Henrik N