I'm a beginner of rails programming. This is my first question in sof. I want to give my nav var "active" class when current page is included in the array of links.
I know how to check 1:1 in application_helper.rb
def is_active?(path)
current_page?(path)? "active" : ""
end
As far as I know, current_page?(x) method only show true/false.
How to check in array?
for example:
<li class="<%= is_active?([a_1_path,a_2_path,a_3_path]) %>">
I tried this:
def is_active?(paths)
y=0
for x in paths
current_page?(x)? (y=1): ""
end
y=1? "active":""
end
but this makes all the menus in nav var active.
Do I have to render other pages in one page to control and keep active class in nav var among multiple pages?
is_active?([a_1_path,a_2_path,a_3_path]
, you are sending more than one paths so inis_active?
you need to loop through each path to check. – Anand