0

i uploaded a pdf file during create a new employee in employeeController but after saving this .i want to download file from show.html.erb by clicking on name of file. show.html.erb

<tr>
    <td><b>Resume:</b></td>
    <td><%=link_to @employee.resume.attach_file_file_name ,download_employee_path(@employee)  ,:class=> "btn btn-link" %></td>
  </tr>

and my method to download file is defined in employee controller.

EmployeeController.rb

def download
    @resume = Resume.where(:employee_id=> params[:id] ).first
    file_path = @resume.attach_file_file_name
    if !file_path.nil?
      send_file "#{Rails.root}/public/system/resumes/attach_files/#{@resume.id}/original/#{file_path}", :X_SendFile => true, :disposition => 'attachment'
    else
      redirect_to profile_url
    end
  end

resume is another table in database. Association: employee has_one resume.

but it does not work.the error is

Cannot read file /RubymineProjects/project2/public/system/resumes/attach_files/1/original/guide.pdf

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
Aniee
  • 81
  • 12
  • Have you checked that `guide.pdf` is present by following `/RubymineProjects/project2/public/system/resumes/attach_files/1/original/guide.pdf` in your project directory ? – jon snow May 08 '15 at 06:16
  • Well i use **send_file @resume.attach_file.path** instead of defining path like that **send_file "#{Rails.root}/public/system/resumes/attach_files/#{@resume.id}/original/#{file_path}", :X_SendFile => true, :disposition => 'attachment' ** in download action of **Employee_Controller.rb** – Aniee May 14 '15 at 05:41
  • Still you getting that problem ? or resolved by using `@resume.attach_file.path` !! – jon snow May 14 '15 at 07:29
  • 1
    its resolved by @resume.attach_file.path – Aniee May 14 '15 at 09:03

0 Answers0