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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:00:58+00:00 2026-05-17T01:00:58+00:00

I am attempting to write this html in haml so as to add an

  • 0

I am attempting to write this html in haml so as to add an id tag if the item is the current one. This is to setup for jquery highlighting.

<% if line_item == @current_item %>
<tr class="line_item id="current_item">
<% else %>
<tr class="line_item">
<% end %> 
  <td><%= line_item.quantity %>&times;</td>
  <td><%= line_item.product.title %></td> 
  <td class="item_price"><%= number_to_currency(line_item.total_price) %></td>
</tr>

Because I don’t want to write a helper method, I’ve stuck the if statement within the tag:

%tr.line_item{ :id => (line_item == @current_item ? '' : 'current_item') }
%td
    = line_item.quantity
%td 
    \x #{line_item.product.title}
%td.item_price
    = number_to_currency(line_item.total_price)
%td.item_remove
    = button_to 'Remove', line_item, :method => :delete

However, this id tag of ‘current_item’ sticks with all the items and not just the current one. This results in javascript highlighting all or the wrong entry. Thoughts on how to get haml to cooperate?

  • 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-17T01:00:59+00:00Added an answer on May 17, 2026 at 1:00 am

    Ehm sir, your condition is wrong 🙂

    It should be

    line_item == @current_item ? "current_item" : ""
    

    There is a thing that’s not pretty – you end up with id="" for rest of the items. But there is a simple cure for it:

    %tr.lineitem{ :id => (line_item == @current_item ? "current_item" : nil)}
    

    When you return nil value for an attribute HAML will ignore it and it will not appear in the output.

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

Sidebar

Related Questions

I am attempting a one page design using loads of jQuery. I have a
Goal: To implement a jQuery plugin for my rails app (or write one myself,
I'm attempting to write a Python function to send an email to a list
So I'm attempting to write a Django reusable app that provides a method for
I dunno guys, this is a really weird one, but I might just be
I'm attempting to clean up data in this (old) spreadsheet and need to remove
I'm fairly new to mod_rewrite and I am attempting to convert a URL from
Hey, I am attempting to use the Microsoft.MSHTML (Version 7.0.3300.0) library to extract the
Hopefully, this will be an easy answer for someone with Javascript time behind them...
I've been able to create a small activex control, but it requires the dll

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.