html - Rails tab selection -


i have tab-like button interface interact site using following html

<li class="current_page_item"><a href="/home" class="first">home</a></li> <li><a href="/projects">projects</a></li> <li><a href="/resume">resume</a></li> <li><a href="/contact">contact</a></li> 

the class="current_page_item attribute changes of tab. each url view managed my staticpages controller, how can make each view have respective 'tab' selected?

current_page?(url) method can you.

create additional helper method.

module applicationhelper   #...   def tab_item(name, url)     opts = {}     opts[:class] = 'current_page_item' if current_page?(url)     content_tag :li, opts       link_to name, url     end   end   #... end 

and use in view

<%= tab_item 'home', root_path %> <%= tab_item 'projects', projects_path %> <%= tab_item 'resume', resume_path %> <%= tab_item 'contact', contact_path %> 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -