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
.
This worked for me:
<%= link_to 'Sitemap', root_url+'my_sitemap.svg', { target: '_blank' } %>
It sounds like you want to access the file here:
<%= link_to "here", "/my_project/data.txt" %>
I'd go with:
link_to 'Download sample', root_path + 'data/invoices/sample.pdf'
Update 2018-08-09
"#{root_path}data/invoices/sample.pdf"
is much simplerIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With