Reputation: 5988
I'm trying to display a logo image with image_tag
, but it always comes up as a broken image.
// application.html.erb
<%= image_tag("logo.png") %>
I have "logo.png" in both /assets/images/logo.png
and /assets/logo.png
and have tried a lot of variations of the URL such as images/logo.png
, /images/logo.png
, assets/images/logo.png
, etc but nothing seems to work.
Any ideas on what I could be doing wrong?
Thank you.
Edit: Addition information
I'm using rails ~> 5.0.1
with bootstrap-sass ~> 3.3.6
.
The file is located at /project_base/app/assets/images/logo.png
.
Running rake assets:clobber & rake assets:precompie
doesn't seem to change anything.
There is no generated asset for logo.png
in /project_base/public/...
.
I haven't changed anything in the development.rb
file, but tried adding:
config.assets.digest = false
config.assets.compile = true
which still doesn't seem to effect the images.
Upvotes: 0
Views: 3252
Reputation: 818
You just need to put your image in assets/images/ and you can load it from any view by
<%=image_tag("logo.png")%>
if rails fails to find your image then it will throw an exception AssetNotFound
Upvotes: 2
Reputation: 16
I had this problem with Rails 5.0.2.
What eventually solved it is changing the version in the following line found, in my case, in config/assets.rb:
Rails.application.config.assets.version = '1.0'
According to http://guides.rubyonrails.org/asset_pipeline.html#upgrading-from-old-versions-of-rails it can be found in config/application.rb as well
config.assets.version = '1.0'
I guess the idea is that every time you update your assets you should update the asset version. I'm not sure it's worth it, so I'll probably will be removing the line completely.
Upvotes: 0
Reputation:
try <%= image_tag 'logo.png' %>
Also, can I see more of your application.html.erb file?
Upvotes: 1