# How do you check for Current Page status?

**URL:** <https://www.ruby-forum.com/t/how-do-you-check-for-current-page-status/117900>\
**Category:** Rails\
**Created:** [October 22, 2007, 8:21am UTC](https://www.ruby-forum.com/t/how-do-you-check-for-current-page-status/117900 "2007-10-22T08:21:24Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [October 22, 2007, 8:21am UTC](https://www.ruby-forum.com/t/how-do-you-check-for-current-page-status/117900/1 "2007-10-22T08:21:24Z")

</div>

I’m incorporating a small navigation bar, and I’d like to highlight the  
current page’s navigation button.

Is there any way to do this?

I tried \<%= “class=‘current’” if current\_page?(page) %\> – but that will  
not work.

Any ideas?

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [October 22, 2007, 8:57am UTC](https://www.ruby-forum.com/t/how-do-you-check-for-current-page-status/117900/2 "2007-10-22T08:57:44Z")

</div>

On Oct 21, 2007, at 11:21 PM, Bob S. wrote:

> I’m incorporating a small navigation bar, and I’d like to highlight  
> the  
> current page’s navigation button.
> 
> Is there any way to do this?
> 
> I tried \<%= “class=‘current’” if current\_page?(page) %\> – but that  
> will  
> not work.

Assuming you’re running straight /controller/action type URLs, I was  
recently told you can get that info by using

controller.action\_name

– gw

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [October 22, 2007, 1:31pm UTC](https://www.ruby-forum.com/t/how-do-you-check-for-current-page-status/117900/3 "2007-10-22T13:31:31Z")

</div>

On 22 Oct, 07:21, Bob S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m incorporating a small navigation bar, and I’d like to highlight the  
> current page’s navigation button.
> 
> Is there any way to do this?

I usually do this through descendant CSS selectors. For example, for  
each page, I will give a unique ID to the body tag (generally based on  
the controller name) and each navigation element has a unique ID.

---- application.rhtml ----

- Index
- Notes

Assuming my controllers share the same name as the href, I would use  
CSS as follows to highlight the current navigation:

#index #index\_nav,  
#notes #notes\_nav {  
font-weight: bold;  
color: red  
}

Best Regards

Robin

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [October 22, 2007, 1:41pm UTC](https://www.ruby-forum.com/t/how-do-you-check-for-current-page-status/117900/4 "2007-10-22T13:41:29Z")

</div>

On Oct 21, 11:21 pm, Bob S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Posted viahttp://www.ruby-forum.com/.  
> some things to look at:

[http://snippets.dzone.com/posts/show/2016](http://snippets.dzone.com/posts/show/2016)

[http://snippets.dzone.com/posts/show/687](http://snippets.dzone.com/posts/show/687)  
[http://rubysnips.com/body-id-s](http://rubysnips.com/body-id-s)

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [October 22, 2007, 1:32pm UTC](https://www.ruby-forum.com/t/how-do-you-check-for-current-page-status/117900/5 "2007-10-22T13:32:42Z")

</div>

> #index #index\_nav,  
> #notes #notes\_nav {  
> font-weight: bold;  
> color: red
> 
> }

Should be:

#index\_body #index\_nav,  
#notes\_body #notes\_nav

Robin

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [October 22, 2007, 2:33pm UTC](https://www.ruby-forum.com/t/how-do-you-check-for-current-page-status/117900/6 "2007-10-22T14:33:45Z")

</div>

[http://railslodge.com/plugins/110-tabnav](http://railslodge.com/plugins/110-tabnav) may be worth a look

Bob S. wrote:

> I’m incorporating a small navigation bar, and I’d like to highlight the  
> current page’s navigation button.
> 
> Is there any way to do this?
> 
> I tried \<%= “class=‘current’” if current\_page?(page) %\> – but that will  
> not work.
> 
> Any ideas?

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [October 22, 2007, 10:49pm UTC](https://www.ruby-forum.com/t/how-do-you-check-for-current-page-status/117900/7 "2007-10-22T22:49:23Z")

</div>

Thanks all! Wonderful resources and ideas. I can’t thank all of you  
enough.

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [October 24, 2007, 2:47am UTC](https://www.ruby-forum.com/t/how-do-you-check-for-current-page-status/117900/8 "2007-10-24T02:47:39Z")

</div>

Hi again guys. Thanks again for the great ideas.

This simple one-liner also worked for me too:

\<%= “class=‘current’” if @controller.request.request\_uri ==  
( **page\_url\_here** ) %\>

---

<div class="post-metadata">

**Author:** ![adistarmid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f14d63/32.png) [@adistarmid](https://www.ruby-forum.com/u/adistarmid)\
**Post date:** [October 23, 2007, 2:46pm UTC](https://www.ruby-forum.com/t/how-do-you-check-for-current-page-status/117900/9 "2007-10-23T14:46:48Z")

</div>

Another option is to user link\_to\_unless\_current helper instead of  
link\_to that will deactivate your link on the current page. Hope that  
helps…

On Oct 22, 7:21 am, Bob S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
