I have the following type of page setup:
Header – Consistent
Left side – contains <%= yield %>
Right side – ul that contains mostly static menu
So, what I would like to do is
a) add a class to the current page li. So for example, when on the about page, about li on the right adds .current
and b) show sub-menu on right side for current page. So if li is about.current, I could show a sub-menu inside that li.
The layout is there for every page (as is the purpose of the application layout), and not every page is listed in the menu on the right. So, the question is can I pass a variable or a call that will pass the page name to the application layout to allow for adding .current or what is the best way to deal with something like this? Is the answer to just not include the right menu bar in the application layout, even though I would then need to add it to every page?
Looking for suggestions.
The
current_page?helper method can tell you if a url is for the current page. So you could do something like the following:Even better, you could define a helper method that will do that automatically:
And then:
http://apidock.com/rails/ActionView/Helpers/UrlHelper/current_page%3F