How do you check for Current Page status?

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?

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

On 22 Oct, 07:21, Bob S. [email protected]
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 ----

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

On Oct 21, 11:21 pm, Bob S. [email protected]
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/687
http://rubysnips.com/body-id-s

#index #index_nav,
#notes #notes_nav {
font-weight: bold;
color: red

}

Should be:

#index_body #index_nav,
#notes_body #notes_nav

Robin

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?

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

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) %>

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. [email protected]