Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails : new asset path for PDF's not being recognised

I have a rails app in which I have added a new asset. I have added a new folder named information, in the assets folder, in which there is a PDF called xyz.pdf.

The problem is that I am trying to make a link to that PDF, however the application throws up an error: No route matches [GET] "/assets/information/xyz.pdf"

I have added the new asset in the config/application.rb file :

config.assets.paths << "#{Rails.root}/app/assets/information"

This is the link I am using :

<%= link_to "Information Pack", "assets/information/xyz.pdf", :class => "links" %>
like image 713
Muhammed Bhikha Avatar asked Nov 27 '12 15:11

Muhammed Bhikha


1 Answers

When using the asset pipeline, you should refer to any asset in the application with:

<%= link_to "Information Pack", asset_path("information/xyz.pdf"), :class => "links" %>

or

<%= link_to "Information Pack", asset_path("xyz.pdf"), :class => "links" %>

This would generate a different path depending the running environment and the asset version number.

like image 129
Tania R Avatar answered Oct 14 '22 21:10

Tania R