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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:15:20+00:00 2026-06-01T14:15:20+00:00

Long time listener, first time caller. I’m a 6 month old dev from Code

  • 0

Long time listener, first time caller. I’m a 6 month old dev from Code Academy here in Chicago, and I’ve been stuck on this problem for a few hours. Beforehand, I appreciate all of your assistance and time.

I’m converting an ERB template to HAML. The ERB is:

<ul class="nav nav-list">
  <li class="nav-header">
    <%= navigation_header %>
  </li>
  <% @navigation_links.each do |link| %>
  <% if link[:name].present? %>
    <li <%= link[:name] == @topic ? "class='active'" : "" %>>
      <%= link_to link[:name], link[:url] %>
    </li>
  <% else %>
    <hr />
  <% end %>
  <% end %>
</ul>

The ERB line I’m having trouble with is:

<li <%= link[:name] == @topic ? "class='active'" : "" %>>

I’ve tested many variations, read as much of the HAML reference as possible, concentrating on this section:

You can also use #{} interpolation to insert complicated expressions
in a HTML-style attribute:

%span(class="widget_#{@widget.number}")

…and searched Google & StackOverflow, but I cannot get the output correct; HAML keeps disregarding the inline CSS. After all my groundwork, I was so confident in this version, but it didn’t work:

- @navigation_links.each do |link|
  - if link[:name].present?
    %li{ :class => "#{ link[:name] == @topic ? "active" : ""}" }
      = link_to link[:name], link[:url]
  - else
    %hr

I’ve also tried an :erb filter, to no avail:

%ul.nav.nav-list
  %li.nav-header
    = navigation_header
- @navigation_links.each do |link|
  - if link[:name].present?
    :erb
      <li <%= link[:name] == @topic ? "class='active'" : "" %>>
    = link_to link[:name], link[:url]
  - else
    %hr

And I’ve also tried a :css filter, but that failed.

Any ideas what could be wrong? This is my first question on StackOverflow, so if I omitted some helpful info or broke any rules, please let me know.

  • 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-01T14:15:21+00:00Added an answer on June 1, 2026 at 2:15 pm
    <li <%= link[:name] == @topic ? "class='active'" : "" %>>
    

    You don’t need variable interpolation. This translates rather easily into HAML as either of the following:

    %li{:class => (link[:name] == @topic) && "active"}
    %li{:class => (link[:name] == @topic) ? "active" : "" }
    

    The first is preferred in cases where you are including or omitting the value altogether. From the HAML docs:

    If a single value is specified and it evaluates to false it is
    ignored; otherwise it gets converted to a string. For example:

    .item{:class => @item.is_empty? && "empty"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Long time listener, first time caller here. Ok, I apologize for the length of
I’m a long time listener, but first time caller here… Hoping you can help
long time listener, first time caller... I am creating a splash screen derived from
As they say on the radio - long time listener first time caller.... Here's
Hey Overflow. Long time listener, first time caller. So here's what I've got: I'm
long time listener first time caller... I have this function (I don;t recall where
Long time listener, first time caller. I'm a full time SE during the day
long-time listener, first-time caller! I’m trying to connect to MySQL using the ADO.NET Entity
Long time listener - first time caller. I am hoping to get some advice.
Long time listener, first time caller… I've got two questions in a form, the

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.