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

  • SEARCH
  • Home
  • 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 692095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:36:54+00:00 2026-05-14T02:36:54+00:00

I have this Haml view: !!! strict %html{:xmlns => http://www.w3.org/1999/xhtml} %head %meta{:content => text/html;

  • 0

I have this Haml view:

!!! strict
 %html{:xmlns => "http://www.w3.org/1999/xhtml"}
   %head
     %meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}
     %title
       Lighty | #{@page_title || "Home"}
   %body
     #popup Login here
     #fade
     #wrapper
       #container
         #header
           %a#logo{:href => "/"}
         #menu
           %ul#main
             %li#lighty
               %a{:href => "/"} Lighty
                 %ul
                    %li
                       %a Link here
             %li#community
               %a{:href => "/community"} Community
        #content

And I would like to add an if on line #16 to check if it is the currently visited page and add the class “active” to the li if it returns true.

How do I write that if statement there and is there any easier way to do this?

My plan now is to use a variable like @current_page and test if @current_page == "community" and add a class if it returns true.

Am I thinking wrong? Is there any easier way to accomplish this?

  • 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-05-14T02:36:55+00:00Added an answer on May 14, 2026 at 2:36 am

    I would highly suggest creating a helper method called visited_class or something similar since it should have access to the current controller/action. Then, you can write all of the code’s logic inside of the helper method. This keeps your views drastically cleaner.

    You can place this in many places, but since I have so few helpers, I usually just drop it in ApplicationHelper:

    def ApplicationHelper
    
      def visited_class(controller, action)
        if params[:controller] == controller && params[:action] == action
          return " active"
        else
          return ""
        end
      end
    
    end
    

    Then, in your view/HAML file, simply call visited_class and pass in the controller/action that you want to check. You might also be able to use a URL parameter and piece it together from the request.request_uri, but that might be a bit more tedious.

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

Sidebar

Related Questions

I have this view: new.html.haml %h1 New account - form_for @user do |f| =
I have a view in this directory: app/views/mobile/dis/my_view.html.haml and in it I have simple
Let's say I have a view, views/layouts/home.html.haml , and I am overriding it with
I have a simple controller that goes to a view under views/mobile/home/index.html.haml It works
I have a Ruby application, and here is my setup: I have this HAML
I have this in one of my haml views: -form_for :news_item_comment, :url=>{:id => comment.id,
I have some HAML code like this: .clearfix =f.label t(labels.shortened_urls.fqdn_url) =f.url_field :fqdn_url, {:readonly =>
Have this self-made slider: http://jsfiddle.net/wyc3P/4/ What it does: takes min and max values in
I have a partial, _flash.html.haml - flash.each do |type, value| .flash{ :class => type.to_s
I have this code: = link_to unsubscribe instantly, *|UNSUB|*.html_safe That generates this HTML: <a

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.