J'ai un chemin pour un fichier sur ma machine pour lequel je voudrais définir le lien de téléchargement. Voici ce que je suis en train:lien pour télécharger le fichier à partir du chemin
Dans mon modèle:
class Exam < ActiveRecord::Base
attr_accessible :data, :full_path
has_attached_file :image,
:path => :full_path
end
mon contrôleur ressemble à ceci:
def download
@exam = Exam.find(params[:id])
send_file @exam.image.path, :x_sendfile => true
end
Et moi:
<%= link_to "Download", download_exam_path(@exam) %>
Maintenant, quand je Cliquez sur télécharger Je reçois cette erreur: can't convert nil into String
Je sais pour un fait que :full_path
contient le chemin d'accès correct à mon fichier. Comment puis-je réparer cela?
pleine erreur:
TypeError in ExamsController#download
can't convert nil into String
Rails.root: /Users/Ryan45/Programming/rails_projects/oldV_rails_project
Application Trace | Framework Trace | Full Trace
app/controllers/exams_controller.rb:83:in `download'
Request
Parameters:
{"id"=>"392"}
Show session dump
Show env dump
Response
Headers:
None
Est-ce que 'send_file @ exam.image.path,: x_sendfile => true' ligne 83 de' exams_controller.rb'? –
Oui, c'est en effet. – DashControl
il suffit de demander, utilisez-vous 'paperclip'? –