Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:00:57+00:00 2026-06-18T06:00:57+00:00

I have a layout with a menu navigation. I’m using a template I found

  • 0

I have a layout with a menu navigation. I’m using a template I found online. There is an HTML page for each menu item and the li item class is called “selected” for each corresponding page. It looks like this:

  <nav>
    <ul class="sf-menu" id="nav">
      <li class="selected"><%= link_to "home", root_path %></li>
      <li><%= link_to "about me", about_path %></li>
      <li><%= link_to "my portfolio" %>
        <ul style="z-index: 2;">
          <li style="z-index: 2;"><%= link_to "portfolio one", portfolio_one_path %></li>
          <li style="z-index: 2;"><%= link_to "portfolio two", portfolio_two_path %></li>
          <li style="z-index: 2;"><%= link_to "portfolio three", portfolio_three_path %></li>
        </ul>
      </li>
      <li><%= link_to "blog", blog_path %></li>
      <li><%= link_to "contact", contact_path %></li>
    </ul>
  </nav>

So this is in my application.html.erb file. My question is how do I programmatically change each li item’s class to “selected” depending on which link the user clicks on? Can this be done with Ruby or do I need to use JavaScript?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:00:58+00:00Added an answer on June 18, 2026 at 6:00 am

    I think you want the current_page? helper method – http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-current_page-3F

    <li class="<%= "selected" if current_page?(root_path) %>"><%= link_to "home", root_path %></li>
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we have a Tiles layout page having Header, Menu, Body and Footer. In this
so I have my main layout as such: <div class=menu> <?php include('/menu.php'); ?> </div>
Hi I have a page with a navigation menu on the left and when
Currently I have a page with navigation menu. This navigation menu get it items
I have a web page with a navigation menu. The current page must be
I have made a helper class called Navigation that gets used on every page
I am attempting to build a Tabbed side navigation menu using html/css. I am
I am using PHP to layout a navigation menu and display content according to
In my app I have a navigation menu that is constant between activities. To
I have some static pages in a navigation menu. I want to add more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.