Question

Right now I have some filler code in a mockup such as the following:

%img{:alt => "image description", :src => "img/img-11.jpg"}

Ideally though, I need to reference img-11.jpg from the asset pipeline as I do in my CSS:

<%= asset_path "img-11.jpg" %>

How does one rewrite the markup above to call asset_path within the context of a HAML template?

Was it helpful?

Solution

HAML is basically the same, but without the surrounding brackets if you're doing it inline:

= asset_path "img-11.jpg"

Otherwise you should be able to use it in the definition:

%img{:alt => "image description", :src => asset_path("img-11.jpg")}

OTHER TIPS

In this case, use = image_tag('img-11.jpg', alt: 'Image Description'), but in the general case, use = function_name_or_ruby_code to evaluate any arbitrary Ruby and output the result.

You can use - ruby_code to evaluate Ruby without outputting the result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top