Reputation: 325
I have something like this in my rails app:
<a class="fancybox" rel="gallery1" href="gal5.jpg" title="something">
<img hspace="12" src="images/gal5thumb.jpg" alt="Something" />
</a>
I have my images saved in /assets/images. For some reason this doesn't work but when I save the images on some website like cloudinary and then use the url everything works perfectly. Can someone please point out what I am doing wrong?
I am using rails 5 on Ubuntu.
Thanks.
Upvotes: 2
Views: 45
Reputation: 6531
=> If you place images in your app/assets/images directory, then you should be able to call the image directly with no prefix in the path. ie. image_url('logo.png')
or asset_url('gal5thumb.jpg')
<a class="fancybox" rel="gallery1" href="gal5.jpg" title="something">
<img hspace="12" src="/assets/gal5thumb.jpg" alt="Something" />
</a>
Or
<a class="fancybox" rel="gallery1" href="gal5.jpg" title="something">
<img hspace="12" src="<%=asset_path('gal5thumb.jpg')%>" alt="Something" />
</a>
Or
=> If you are using it inline in the view, then you will need to use the built in image_tag helper in rails to output your image. without prefixing
<%= image_tag "gal5thumb.jpg", alt: "something", hspace: "12" %>
Upvotes: 2