BartlomiejSkwira
5/3/2013 - 2:38 PM

Paperclip - Download file path

Paperclip - Download file path

#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