Site structure:
/
/products
/products/design
/products/photo
/about
I want to see parent menu item also highlighted by CSS, when child is active.
(When 'design' or 'photo' is active 'products' should be highlighted too.)
I'm using this for child and simple urls:
<li class="<%= current_page?(:action => 'design') %>">
<%= link_to_unless_current 'Design', :design %>
</li>
For 'products' checking should be like:
<%= current_page?(:action => 'products') ||
current_page?(:action => 'design') %> ||
current_page?(:action => 'photo') %>
But triple || is not right, and it's become complicated.
I saw a helper, like this one:
def current(childs)
if current_page?(:action => childs)
@container = "active"
else
@container = "inactive"
end
end
Which is used by: <%= current(:photo) %>
So, how to put all my 3 checks for 'products', 'design', 'photo' in one helper?
And make possible to use something li开发者_JAVA技巧ke <%= current(:products, :design, :photo) %>
I wouldn't recreate the wheel and use a Rails menu-builder gem/plugin like simple-navigation.
Here's a demo of navigation and styling.
精彩评论