How do I make dynamic ids in Haml?

There are two ways:

The long form way (define the id as if it were a regular attribute):

.box{:id => "item_#{x}"}

produces this (x is what ever x.to_s evaluates to):

<div class="box" id="item_x">

The short form way:

.box[x]

produces the following assuming x is an instance of item:

<div class="box item" id="item_45">

See the HAML reference for more information.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)