Topic: using "send_file" creates error "Cannot read file"

i am trying to implement a filedownload into my application.
as seen in the api i used send_file this way ->

first there is a link to the action

<%=  link_to image_tag("/post_files/#{}/thumbnails/#{post_file.file_name}", :border=>0) + post_file.file_name, :action => 'show_attachment', :id => %>

the action
  def show_attachment

    @attachment = PostFile.find(params[:id])
    send_file  "/public/post_files/#{@attachment.post_id}/#{@attachment.file_name}"


now clicking the link i get this error

ActionController::MissingFile in BlogsController#show_attachment 
Cannot read file /public/post_files/4/1.png

the path dont seem to be the problem, i tryed paths with the same result.

thanks for help

Re: using "send_file" creates error "Cannot read file"

ok i found a solution
the way described in the api didnt work in my case
but it worked with a complete path like this

send_file "#{RAILS_ROOT}/public/post_files/#{@attachment.post_id}/#{@attachment.file_name}"

Re: using "send_file" creates error "Cannot read file"

That's because you specified an invalid absolute path - /public usually doesn't exist in a Unix-based system. send_file always takes an absolute path.
And btw. there are two cool plugins that take away some of the pain when it comes to handling file uploads/downloads in Rails: Paperclip and attachment_fu.

Visit for quality Rails contract work. We also blog about Rails, AJAX and other things.

Re: using "send_file" creates error "Cannot read file"

Hi, i'm new to rails, in my application i want to provide a download for users, in which they can download files in the format of zip file, whenever i m trying click download link it shows the message as below