# Check if current route == some route

**URL:** <https://www.ruby-forum.com/t/check-if-current-route-some-route/58571>\
**Category:** Rails\
**Created:** [April 23, 2006, 2:23pm UTC](https://www.ruby-forum.com/t/check-if-current-route-some-route/58571 "2006-04-23T14:23:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrik\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c68b51/32.png) [@Henrik\_N](https://www.ruby-forum.com/u/Henrik_N)\
**Post date:** [April 23, 2006, 2:23pm UTC](https://www.ruby-forum.com/t/check-if-current-route-some-route/58571/1 "2006-04-23T14:23:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Henrik\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c68b51/32.png) [@Henrik\_N](https://www.ruby-forum.com/u/Henrik_N)\
**Post date:** [April 23, 2006, 2:32pm UTC](https://www.ruby-forum.com/t/check-if-current-route-some-route/58571/2 "2006-04-23T14:32:09Z")

</div>

> > > > > “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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.livejournal.com/users/cdybedahl/](http://www.livejournal.com/users/cdybedahl/)  
“Just about anything can be done if you are demented enough.”  
– Christopher C. Petro, scary.devil.monastery

---

<div class="post-metadata">

**Author:** ![Henrik\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/c68b51/32.png) [@Henrik\_N](https://www.ruby-forum.com/u/Henrik_N)\
**Post date:** [April 23, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/check-if-current-route-some-route/58571/3 "2006-04-23T17:00:59Z")

</div>

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
