Rails 3: Image broadcast error: "Image ... can not be displayed because it contains errors"

advertisements

The log says:

Started GET "/assets/2/thumb" for 110.174.88.80 at Fri Jul 01 20:11:35 -0700 2011
  Processing by AssetsController#show as HTML
  Parameters: {"id"=>"2", "style"=>"thumb"}
[/home/misha_moroshko/myfamily.moroshko.com/public/images/thumb.jpg] found!
Sent file /home/misha_moroshko/myfamily.moroshko.com/public/images/thumb.jpg (0.2ms)
Completed 200 OK in 2ms

If you go directly to the image, it is fetched properly.

Note that this is a simplified example of my real problem. In the real case the image is not in the public folder, but the error is the same.

What could cause such an error ?


rails -v
=> Rails 3.0.1
ruby -v
=> ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]


Relevant code:

# config/routes.rb
match "assets/:id/:style" => "assets#show"

class AssetsController < ApplicationController
  def show
    path = Rails.root.join("public", "images", "thumb.jpg").to_s
    if File.exist?(path)
      logger.fatal "[#{path}] found!"
      send_file(path, { :type => "image/jpeg", :disposition => "inline" })
    else
      logger.fatal "[#{path}] not found!"
    end
  end
end


Replacing

config.action_dispatch.x_sendfile_header = "X-Sendfile"

with

config.action_dispatch.x_sendfile_header = "X-Accel-Redirect"

in config/environments/production.rb solved the problem!