Reputation: 51
<%= image_tag("/public/pool_2.jpg") %>
it found the image, but there is no picture
I checked the assets.paths in rails console, and it does include "/public" directory in the assets.paths
rails c
Rails.application.assets.paths
...
vice/home_service/public", ...
Upvotes: 0
Views: 1070
Reputation: 51
No, I didn't move my carrierwave uploads to /public for some reason. I also changed in /config/application.rb
config.public_file_server.enabled = true
and I doubled checked the value of config.public_file_server.enabled on rails console. But Rails 5 still doesn't like to display static images like /public/image.png.
So I just sub the "/app/assets/images" part out, then it works. Now the image is displayed. Here is my hack:
<% @image_src = @profile.avatar.url(:thumb).sub(/\/app\/assets\/images\//, "") %>
<%= image_tag @image_src %>
<%#= image_tag @profile.avatar.url(:thumb) %>
Upvotes: 1
Reputation: 10349
I would recommend placing the image in /public/assets/images in order to mirror the structure of app/assets, for consistency's sake.
In your view, you could then use:
<%= image_tag '/assets/images/pool_2.jpg' %>
Also, be sure that config.public_file_server.enabled
is set to true
in config/application.rb.
You should review the How to Use the Asset Pipeline section of the Asset Pipeline docs.
Upvotes: 0