Reputation: 97
I'm sure there are many post like this but after to check them I wasn't found anyone to answer my issue.
Im trying to get an image located at "app/assets/images/levers/I.a.1.png"
with a link_to
like this:
<%= link_to("Biomasa", image_path("levers/I.a.1.png"), :target => "_new") %>
No matter how many times I tried with differents combinations of the path, it doesn't work. I'm getting this error:
The asset "levers/I.a.1.png" is not present in the asset pipeline.
There are something I'm missing or doing wrong?
More information
I'm not sure if is important but im using "Bash on Ubuntu on Windows" to make all possible from my windows 10 (at work obiously).
Upvotes: 0
Views: 3031
Reputation: 97
Finally i solve this. The problem was a case sensitive in the extension of my images. It was .PNG
and I was trying .png
Upvotes: 0
Reputation: 6952
You can pass a block to link_to
. Try this:
<% link_to('/wherever/you/want/to/link-to', :target => '_new') do %>
<%= image_tag('I.a.1.png', alt: 'Biomasa') %>
<% end %>
Image tag should look in app/assets/images
automatically, so this will add the remainder of the path.
Add this to config/initializers/assets.rb
Dir.glob("#{Rails.root}/app/assets/images/**/").each do |path|
Rails.application.config.assets.paths << path
end
and you should be good to go.
Upvotes: 0
Reputation: 3603
add this config to your application.rb
to include files inside app/assets/images
into asset pipeline
config.assets.paths << Rails.root.join("app", "assets", "images", "levers")
Then, on your rails view, you can use link_to
with asset_path
<%= link_to root_path, :target => "_blank" do %>
<%= image_tag asset_path("I.a.1.png") %>
<% end %>
Upvotes: 1