3

Just adopted an application using HAML and trying to write on top of it (never used HAML before). Been looking at different resources like haml.info and this S.O post. However, the S.O. post is actually incorrect in a couple ways. I'm trying to render your basic bootstrap flash messages.

So far I have this structure:

- flash.each do |key, value|
  .alert.alert-dismissable{ :class => 'alert-#{key}' }
    %button.close{ :type => 'button', :data => { :dismiss => 'alert' }, :aria => { :hidden => 'true' } }
      %i.icon-remove-sign
    = value

Yea that's right, I have to go back to Bootstrap 2 on this one. Seems like everything works, except this line here:

.alert.alert-dismissable{ :class => 'alert-#{key}' }

This gets rendered to HTML as

<div class="alert alert-#{key} alert-dismissable">

Obviously, I want #{key} to be replaced with the key coming from the controller (success, danger, notice, etc) Would love to know what is wrong here. Thanks for taking a look at it.

1 Answer 1

3

"alert-#{key}"

In ruby you can't use #{} to escape single quoted strings.

Sign up to request clarification or add additional context in comments.

3 Comments

Don't I look dumb. Thanks @Baloo. Will accept when I can.
I wouldn't worry about it, I had a similar moment earlier today
Happens to the best of us.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.