# Help on formatting some HAML

**URL:** <https://www.ruby-forum.com/t/help-on-formatting-some-haml/194609>\
**Category:** Rails\
**Created:** [September 7, 2010, 10:25pm UTC](https://www.ruby-forum.com/t/help-on-formatting-some-haml/194609 "2010-09-07T22:25:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hazmatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@hazmatt](https://www.ruby-forum.com/u/hazmatt)\
**Post date:** [September 7, 2010, 10:25pm UTC](https://www.ruby-forum.com/t/help-on-formatting-some-haml/194609/1 "2010-09-07T22:25:04Z")

</div>

I wondered if anyone could help me with turning the following in ERB  
into HAML. I’m VERY new with HAML:

* * *

\<%= link\_to "New Order", new\_order\_path, :remote =\> true %\>
### Today's Activity

* * *

 \<% @orders.each do |order| %\> - \<%= "#{leading\_zeros order.id}" %\> \<%= link\_to "#{order.name}", order, :remote =\> true %\>
\<%= link\_to 'Delete', order, :confirm =\> 'Are you sure?', :method =\> :delete %\>- \<%= distance\_of\_time\_in\_words\_to\_now(order.created\_at, :include\_seconds =\> true) %\> ago
 \<% end %\> 

 Pagination goes here 
  

* * *

I have tried it a few different ways to convert this to HAML, but I’m  
messing it up on this secion (which is the meat of the document):

* * *

\<% @orders.each do |order| %\>- \<%= "#{leading\_zeros order.id}" %\> \<%= link\_to "#{order.name}", order, :remote =\> true %\>
 \<%= link\_to 'Delete', order, :confirm =\> 'Are you sure?', :method =\> :delete %\>- \<%= distance\_of\_time\_in\_words\_to\_now(order.created\_at, :include\_seconds =\> true) %\> ago

\<% end %\>

## 

I have it in HAML as:

* * *

%ul= @orders.each do |order|  
%li  
%span.pull-2.box= “#{leading\_zeros order.id}”  
= link\_to “#{order.name}”, order, :remote =\> true  
%span.rightside= link\_to ‘Delete’, order, :confirm =\> ‘Are you sure?’,  
:method =\> :delete  
%li.time\_space  
%span.quiet.small.time=  
{distance\_of\_time\_in\_words\_to\_now(order.created\_at, :include\_seconds =\>  
true)} ago  
= end

* * *

I’m not sure how to correct this. Any help on formatting the ruby code  
would be greatly appreciated. That’s where it seems to fail on me. I  
have multiple spans on the same line in ERB. Should I do each span on  
its own line?

---

<div class="post-metadata">

**Author:** ![hazmatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@hazmatt](https://www.ruby-forum.com/u/hazmatt)\
**Post date:** [September 7, 2010, 10:35pm UTC](https://www.ruby-forum.com/t/help-on-formatting-some-haml/194609/2 "2010-09-07T22:35:25Z")

</div>

Matt R. wrote:

> I wondered if anyone could help me with turning the following in ERB  
> into HAML.

Do you mean ERb and Haml? 🙂

> I’m VERY new with HAML:

Run it through html2haml and see what you get. Note, however, that it  
will usually produce

%span  
= content

where you generally want

%span= content

Other than that, it’s great to help you get started.

[…]

> I have tried it a few different ways to convert this to HAML, but I’m  
> messing it up on this secion (which is the meat of the document):
> 
> * * *
> 
> \<% @orders.each do |order| %\>- \<%= "#{leading\_zeros order.id}" %\> \<%= link\_to "#{order.name}", order, :remote =\> true %\>
> \<%= link\_to 'Delete', order, :confirm =\> 'Are you sure?', :method =\> :delete %\>- \<%= distance\_of\_time\_in\_words\_to\_now(order.created\_at, :include\_seconds =\> true) %\> ago
> 
> \<% end %\>
> 
> ----
> 
> I have it in HAML as:
> 
> * * *
> 
> %ul= @orders.each do |order|  
> %li  
> %span.pull-2.box= “#{leading\_zeros order.id}”  
> = link\_to “#{order.name}”, order, :remote =\> true  
> %span.rightside= link\_to ‘Delete’, order, :confirm =\> ‘Are you sure?’,  
> :method =\> :delete  
> %li.time\_space  
> %span.quiet.small.time=  
> {distance\_of\_time\_in\_words\_to\_now(order.created\_at, :include\_seconds =\>  
> true)} ago  
> = end

That’s not even close to right. You need to learn about the use of -  
instead of = in Haml. Reread the language reference.

> * * *
> 
> I’m not sure how to correct this. Any help on formatting the ruby code  
> would be greatly appreciated. That’s where it seems to fail on me. I  
> have multiple spans on the same line in ERB. Should I do each span on  
> its own line?

Yes. Haml has no notion of multiple elements on one line. If white  
space is an issue, you can use Haml’s \< and \> modifiers – or include  
bits of HTML or ERb if you really need to (it is _occasionally_  
necessary to do so).

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![hazmatt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b2d939/32.png) [@hazmatt](https://www.ruby-forum.com/u/hazmatt)\
**Post date:** [September 7, 2010, 10:43pm UTC](https://www.ruby-forum.com/t/help-on-formatting-some-haml/194609/3 "2010-09-07T22:43:01Z")

</div>

Marnen Laibow-Koser wrote:

> Run it through html2haml and see what you get. Note, however, that it  
> will usually produce
> 
> %span  
> = content
> 
> where you generally want
> 
> %span= content
> 
> Other than that, it’s great to help you get started.

PERFECT! Thanks Marnen!
