Ruby on Rails
Tuesday, February 1, 2011
On 01 Feb 2011, at 14:41, Tushar Gandhi wrote:
I am uploading a PDF file using paper clip. File get uploaded
successfully. If I try to view the file directly from file system it is
opening.
I have to open the file from application so I have written following
code.
View Code:-
<%= link_to 'View Attachment', {:action=>"show_attachment",
:id=>user.id} %>
Controller Code:-
def show_attachment
@user=User.find(params[:id])
send_data(@user.attachment.url, :type => "application/pdf",
:filename => "attachment.pdf", :disposition => 'attachment')
end
Can anyone tell me what is the issue?
I can see the pdf file from the uploaded location.
You probably need to use the path instead of the url for sending files:
send_data(@user.attachment.path, :type => "application/pdf",
:filename => "attachment.pdf", :disposition => 'attachment')
:filename => "attachment.pdf", :disposition => 'attachment')
Best regards
Peter De Berdt
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment