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