Search code examples
ruby-on-railsrubyruby-on-rails-3haml

div title syntax in haml and also incorporate ruby variable inside it


I have trouble converting HTML syntax into HAML.

I know a <div> class can be simply represented by:

.class-name

But, I want to convert the following syntax into HAML and also incorporate a variable in the title:

<div title="My title" class="my-text">This is my title</div>

Something like:

.title{@ruby-variable}.my-text

Solution

  • .my-text{:title => "My title"} This is my title
    

    in haml you use #someid.someclass{:custom_attr => "something"}. :costum_attr can also be a class or a id if you need to define it dynamically.