Last active
December 16, 2015 22:49
-
-
Save BartlomiejSkwira/5509506 to your computer and use it in GitHub Desktop.
Paperclip - Download file path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #routes | |
| member do | |
| get :download | |
| end | |
| #model | |
| has_attached_file :gpx, | |
| path: ":rails_root/assets/:class/:id_partition/gpx/route#:id-:basename.:extension", | |
| dependent: :destroy | |
| #controller | |
| def download | |
| head(:not_found) and return if (object = Route.find_by_id(params[:id])).nil? | |
| style = params[:style] | |
| path = object.gpx.path(style) | |
| head(:bad_request) and return unless File.exist?(path) | |
| send_file_options = { type: 'application/gpx+xml' } | |
| send_file(path, send_file_options) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment