MAC
MAC

Reputation: 686

How to use image_url in rails to show images in production?

I have this code

<div class="w-col w-col-7 w-col-stack w-hidden-small w-hidden-tiny col-spc">
     <div class="nivo-slice" style="left: 0px; width: 900px; height: 100%; opacity: 1;">
          <img src="/assets/home/toppho08.jpg" alt="toppho08.jpg">
     </div>

</div>

and it work well in development but when i tried to run it in production, images won't be displayed. So, I was told to use image_url but it html seems to not accept the code. I have this instead and it went okay.

<img src="http://sitename.com/assets/home/toppho08.jpg" alt="toppho08.jpg">

But I want to use the image_url. How do I apply image_url in html?

These links do not answer my question http://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html http://awardwinningfjords.com/2009/05/11/simplify-image-paths-with-image_url.html https://ellislab.com/forums/viewthread/54731/#268424 Rails 4 not right path for image_url

Upvotes: 0

Views: 7316

Answers (2)

Gaurav Gupta
Gaurav Gupta

Reputation: 475

Just use this it will work for you:

<%= image_tag 'home/toppho08.jpg' %>

or

<%= image_tag image_url('home/toppho08.jpg') %>

Upvotes: 3

jon snow
jon snow

Reputation: 3072

Following is enough to use image_tag

<%= image_url 'home/toppho08.jpg' %>

Upvotes: 1

Related Questions