Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails download file from public folder

In my local, I have written

   <%= link_to 'App', "/App.apk", data: { no_turbolink: true } %>

It is working fine simply downloading App.apk file which is present in public folder

But on production, the same link gives the error

 Not Found

 The requested URL /App.apk/ was not found on this server.

Can anyone give me any idea why this is behaving differently on different environment

Thankyou in advance

like image 732
anjali Avatar asked Oct 20 '25 02:10

anjali


1 Answers

Instead of adding path in direct link, create one action which download the file from public folder.

routes.rb

get 'download_apk'

in your controller add below action which downloads apk file

def download_apk
  send_file("#{Rails.root}/public/App.apk")
end
like image 141
Vishal Avatar answered Oct 21 '25 17:10

Vishal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!