stackjlei
stackjlei

Reputation: 10035

Rails image asset tag helper

In rails you can just a regular html img tag in your templates, what is the purpose of using an asset tag helper?

<%= image_tag "header.png" %>

vs.

<img src="header.png">

Upvotes: 0

Views: 581

Answers (2)

tthomas7
tthomas7

Reputation: 46

I think the image_tag also uses the asset path helpers. So it will automatically use '/assets/header.png'. Also if you have asset digest turned on I think it will automatically use '/assets/header-asdfasd.png' on production.

Upvotes: 1

Yuan Z
Yuan Z

Reputation: 333

Actually, any image_tag would be transformed into HTML img tag.

I think Rails just provides some way to create HTML in Ruby/Rails way in case you are not a HTML guy, of course you can just use HTML img tag if you like.

Not only Rails, some other render utils, like Razor in C# , provide the similar feature.

Upvotes: 1

Related Questions