Rails link to file in public folder

Paul S. picture Paul S. · May 29, 2013 · Viewed 21.4k times · Source

I have a file data.txt in the public folder of my Rails project. I want to link to it from one of the pages in my project using link_to. How can I do it?

If I do

<%= link_to "here", "data.txt" %>

it links to domain.com/data.txt instead of domain.com/my_project/data.txt.

Answer

Chris picture Chris · Mar 26, 2014

This worked for me:

<%= link_to 'Sitemap', root_url+'my_sitemap.svg', { target: '_blank' } %>