I'm new to haml, so I'm still trying to figure out the formatting.
I have an index.haml file with the following code.
%h1
Welcome to Solidarity
Hello,
= @profile.first_name
!
It renders like this:
Welcome to Solidarity
Hello, user !
Here's the page source:
<h1>
Welcome to Solidarity
</h1>
Hello,
frances
!
It has a space between @profile.first_name and the exclamation mark. Why is that? And, how do I fix it?
%h1 Welcome to Solidarity
Hello, #{@profile.first_name}!
Please #{link_to 'post a comment', new_comment_path}!
becomes
<h1>Welcome to Solidarity</h1>
Hello, John!
Please <a href="/comments/new">post a comment</a>!
Please keep in mind that in Rails 2 and Haml 2, you must properly html-escape anything you send to the browser (ht nex3):
Hello, #{h @profile.first_name}!
In Rails 3 and Haml 3, everything is escaped by default, so you can simply do:
Hello, #{@profile.first_name}!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With