Hi all.
I've the following navbar on my site:
<div id="nav">
<ul>
<li id="current"><%= link_to "Home", home_url
%></li>
<li><%= link_to "Link 1", link1_url %></li>
<li><%= link_to "Link 2", link2_url %></li>
<li><%= link_to "Link 3", link3_url %></li>
<li><%= link_to "Link 4", link4_url %></li>
<li><%= link_to "Link 5", link5_url %></li>
</ul>
</div>
My question is: what's the best approach against id="current"? I mean: I want to my current controller to be the current "selected" item.
I was thinking about use something like my.url/?current=item_name and an helper. So:
#app/helpers/home_helper.rb def output_li(name, current, &content) output = "<li" output = (name.to_upper == current.to_upper) ? ' id="current"' : '' output = ">"
output = yield
output = "</li>" end
#app/views/layouts <div id="nav"> <ul> <%= output_li "home", params[:current] { link_to "Home", home_url(:current="home") } %> <%= output_li "link1", params[:current] { link_to "Link 1", link1_url(:current="link1") } %> <%= output_li "link2", params[:current] { link_to "Link 2", link2_url(:current="link2") } %> <%= output_li "link3", params[:current] { link_to "Link 3", link3_url(:current="link3") } %> <%= output_li "link4", params[:current] { link_to "Link 4", link4_url(:current="link4") } %> <%= output_li "link5", params[:current] { link_to "Link 5", link5_url(:current="link5") } %> </ul> </div>
What about my solution? I believe that there is an best approach than it, since I unfamiliar with "view logic".
Sorry for my poor English.
Best regards,
davi vidal