HAML and Ajax in Lists

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:

<div id="item034">abc</div>

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?


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.

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.


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

<div class='item' id='item_32'></div>

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.


s.ross wrote: