In my Ruby on Rails 4
application I want to provide the user with a download for a png image.
Firstly, where would this png need to be placed:
- /public
- /assets/images
Secondly, how would I do that?
I've tried what the 2nd answer here says, and I am getting this error:
No route matches [GET] "/public/diagram.png"
The implementation of the above answer:
At my view:
<%= link_to "DOWNLOAD", "/public/diagram.png" %>
The controller:
class ControllerNamesController < ApplicationController
// other actions defined: index, show, create, new, edit, update, destroy
def download_png
send_file(
"#{Rails.root}/public/diagram.png",
filename: "diagram.png",
type: "application/png"
)
end
Τhe routes file (has all the controllers defined like this):
resources :ControllerName
get "ControllerName/download_png", as: :download