# HAML and Ajax in Lists

**URL:** <https://www.ruby-forum.com/t/haml-and-ajax-in-lists/70141>\
**Category:** Rails\
**Created:** [September 27, 2006, 12:44am UTC](https://www.ruby-forum.com/t/haml-and-ajax-in-lists/70141 "2006-09-27T00:44:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [September 27, 2006, 12:44am UTC](https://www.ruby-forum.com/t/haml-and-ajax-in-lists/70141/1 "2006-09-27T00:44:15Z")

</div>

Hi! I have decided to go ahead with HAML and in some ways it feels  
natural,  
and in others I feel I am missing something important. Here’s my  
question du  
jour:

I have a list of catalog items each of which people can add to a cart.  
When  
they add an item, I want a little snippet below the item image to update  
the  
count of that item. E.g. (7 pairs of these shoes in your cart). I’m  
using  
link\_to\_remote and rjs to update, but it requires that I have  
programmatically named DOM elements. Such as:

abc

I don’t see how to explain to HAML that I want to specify the id at  
runtime.

%item{:id =\> ???}

doesn’t give me an opportunity to evaluate an expression as the list  
item is  
being evaluated. How are others solving this problem?

## Thanks

View this message in context:  
[http://www.nabble.com/HAML-and-Ajax-in-Lists-tf2341662.html#a6517355](http://www.nabble.com/HAML-and-Ajax-in-Lists-tf2341662.html#a6517355)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [September 27, 2006, 9:56am UTC](https://www.ruby-forum.com/t/haml-and-ajax-in-lists/70141/2 "2006-09-27T09:56:22Z")

</div>

This should work:

%item{:id =\> “item#{counter}”}

I’m using something like this:  
%tr.{:class =\> “#{even\_odd(counter)}”}

for even-odd class names for table rows.

---

<div class="post-metadata">

**Author:** ![cwd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/da6949/32.png) [@cwd](https://www.ruby-forum.com/u/cwd)\
**Post date:** [October 18, 2006, 3:15pm UTC](https://www.ruby-forum.com/t/haml-and-ajax-in-lists/70141/3 "2006-10-18T15:15:55Z")

</div>

Sorry for the tardy reply. I didn’t see this post.

We have implemented RJS style “simplyhelpful” helpers with dom-element  
naming. Check out the README file (almost a tutorial) to see all of the  
stuff you can do with HAML.

%div[@item]

Assuming item is of class Item and id=32, then that would print

I’m actually confused by your comment that you can’t evaluate the  
attributes { } during run time. They absolutely _are_ evaluated at  
runtime. You are free to do #item{:id =\> @item.id}… we are just  
providing a helper with [] to doing that and use rails-standard naming  
practices.

-hampton.
