Rails link to file in shared folder

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

If i do

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

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

+4
source share
3 answers

It looks like you want to access the file here:

 <%= link_to "here", "/my_project/data.txt" %> 
+5
source

This worked for me:

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

I would go with:

 link_to 'Download sample', root_path << 'data/invoices/sample.pdf' 
  • _url is not required here.
  • << joins the line, and + creates a new
+2
source

Source: https://habr.com/ru/post/1483266/


All Articles