Forum: Ruby on Rails Check if current route == some route

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.
4a551074ddba4460f95d011c47190d0e?d=identicon&s=25 Henrik N (Guest)
on 2006-04-23 14:23
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
9d7d8ef2179661d6b30e180fa588cd45?d=identicon&s=25 Calle Dybedahl (Guest)
on 2006-04-23 14:32
(Received via mailing list)
>>>>> "Henrik" == Henrik N <Henrik> 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 Dybedahl <calle@cyberpomo.com>
		 http://www.livejournal.com/users/cdybedahl/
	"Just about anything can be done if you are demented enough."
		-- Christopher C. Petro, scary.devil.monastery
4a551074ddba4460f95d011c47190d0e?d=identicon&s=25 Henrik N (Guest)
on 2006-04-23 17:00
Calle Dybedahl 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
This topic is locked and can not be replied to.