hazel_jester hazel_jester - 1 month ago 13
Ruby Question

image_tag gives different result for the same path

Basically I have

= image_tag('procedure_icons/chemical/chemical.png')


which gives expected result, proper
html


<img src="/assets/procedure_icons/chemical/chemical-7eee22622b56126c0339a1c340bd4708ca689031ea6448a132c5c004beb32e78.png" alt="Chemical">


but when I try something like this

= image_tag(object.icon_path)


where
icon_path
is draper decorator method

def icon_path
"/procedure_icons/#{object.icon_type}/#{object.icon_type}.png"
end


generated
html
is different

<img src="/procedure_icons/chemical/chemical.png" alt="Chemical">


Can anyone explain this?

T J T J
Answer

The first image_tag is being passed 'procedure_icons/chemical/chemical.png' which the asset pipeline can recognize and thus the source is the image as processed by the asset pipeline.

The second image_tag is being passed '/procedure_icons/chemical/chemical.png' which is just telling rails to use the specific path passed into the helper (notice the proceeding backslash)

Comments