I've got a bunch of files in public/downloads/ directory now how do I get url for them?
P.S. doing just /downloads/xyz.tar.bz2 won't do, because app can be deployed to sub URI.
UPD I've found a dead simple solution:
def public_url(file)
root_url + file
end
I think normalocity was almost right here, but it should rather be root_path
than Rails.root
.
<%= link_to "The file", root_path+"/downloads/test.txt" %>
That should match whatever sub-uri your app resides under, and then append the path to the static file to it.
link_to "The file", asset_path("downloads/test.txt")
asset_path
Computes the path to asset in public director since Rails 4, I believeasset_path
documentationIf 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