i started learn HAML: and i can\'t translate flash block to HAML:
<% flash.each do |key, value| %>
\">
Here you go:
= flash.each do |key, value|
.alert{ :class => "alert-#{key}" }
%button.close{ :data => { :dismiss => "alert" } } x
%strong
= value
Just FYI you can add attributes to any element by attaching them as a hash after the declaration. If you don't specify an element, just a class or ID, HAML makes that element a div with the given class or id. But you could do this many ways. For instance, these are all the same:
%div{:class => 'foo bar', :id => 'test' }
.foo{:class => 'bar', :id => 'test'}
#test.bar{:class => 'foo'}
#test.foo.bar
All output: <div class="foo bar" id="test"></div>
You need to put computed attributes in the hash though, i.e.:
- klass = "bar"
%div{ :class => klass }
Outputs: <div class="bar"></div>
Also, note that in all the examples above, the :attribute => 'value'
can be expressed as attribute: 'value'
, e.g.:
%button.close{ data: { dismiss: 'alert' } } x
Hope that helps.