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 7822889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:03:50+00:00 2026-06-02T08:03:50+00:00

I am trying to use a basic current_page method to define whether a navigation

  • 0

I am trying to use a basic current_page method to define whether a navigation link should be highlighted as the current page or not.

I am not receiving any errors at the moment but am clearly not defining things properly as it’s not using my CSS correctly.

In my PagesController I have the following:

def current_page
  current_page = (path)
end

and I am using an if and else statement on my pages view to try and define which CSS line to use which looks like this:

<div id="nav">
  <ul>
    <li>
      <% if "current_page" %>
        <a href="/about" class="about-cp">About</a>
      <% else %>
        <a href="/about" class="about">About</a>
      <% end %>
    </li>
  </ul> 
</div>

I have read quite a few forums on this but still can’t seem to get it right.

  • 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-02T08:03:51+00:00Added an answer on June 2, 2026 at 8:03 am

    Mhh you got an error in your code. With if "current_page" you will get always true, and only the first link will get rendered. You should use if current_page instead.

    But rails has a build in helper, called current_page? for exactly this purpose:

    Just do it like this:

     <% if current_page?(path) %>
       <a href="/about" class="about-cp">About</a>
     <% else %>
       <a href="/about" class="about">About</a>
     <% end %>
    

    See here for more information on current_page?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use operator overloading to define the basic operations (+,-,*,/) for my
We are trying to use a basic @OneToMany relationship: @Entity @Table(name = PARENT_MESSAGE) public
I'm trying to use FireWatir (1.6.5) to access a site using Basic Authentication and
So, I'm trying to use Doctrine to retrieve some data. I have some basic
General use case I am trying to implement a basic shell. Description I need
I am trying to get a basic understanding on how to use fputc in
I am trying to use some basic SQL functions. I need to get an
I am trying to use a very basic smooth scrolling feature with jQuery's scrollTop
I'm trying to use the Image control is a very basic way, like here:
I'm trying to add a link to a basic MvcScaffolding project that outputs all

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.