Multi level menu, active links css highlight. (Ruby on Rails)
Posted
by klamath
on Stack Overflow
See other posts from Stack Overflow
or by klamath
Published on 2010-05-09T15:35:04Z
Indexed on
2010/05/09
15:38 UTC
Read the original article
Hit count: 165
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 like <%= current(:products, :design, :photo) %>
© Stack Overflow or respective owner