Posted about 11 years ago. Visible to the public. Repeats.

Know your Haml comments

There are two distinct ways of commenting Haml markup: HTML and Ruby.

HTML comments

This will create an HTML comment that will be sent to the client (aka browser):

Copy
/= link_to 'Example', 'www.example.com' # => <!-- = link_to 'Example', 'www.example.com' -->

Only use this variant if you need the comment to appear in the HTML.

Ruby comments

This will comment code so it will not be sent to the client:

Copy
-# = link_to 'foo'

99% of the time you'll be adding notes for other developers, or disabling code sections that should not be sent to the client.

Prefer using -# (which is actually: - "start a Ruby block" + # "Ruby comment").

Warning

This type of comments needs to be indented properly. If you get a syntax error (sometimes a very unhelpful one, echoing the whole file without giving a specific line number), don't forget to check the comments.

Your development team has a full backlog of feature requests, chores and refactoring coupled with deadlines? We are familiar with that. With our "DevOps as a Service" offering, we support developer teams with infrastructure and operations expertise.

Owner of this card:

Avatar
Arne Hartherz
Last edit:
22 days ago
by Klaus Weidinger
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more