4

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
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746

2 Answers2

5

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!

Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
0

The URL http://www.myfamily.moroshko.com/assets/2/thumb is sending the correct headers, but is not sending a body in the response. Have you removed the code that @amb suggested you add? It seems like it's going into your else block and just logging an error to your console.

d11wtq
  • 34,788
  • 19
  • 120
  • 195
  • Please check it now. I see: `[/home/misha_moroshko/myfamily.moroshko.com/public/images/thumb.jpg] found!` – Misha Moroshko Jul 02 '11 at 04:10
  • Still not getting a response body. You can try it with `curl -i http://www.myfamily.moroshko.com/assets/2/thumb` on the command line (on a Mac/Linux). – d11wtq Jul 02 '11 at 04:13
  • Well, probably this is the problem. The question is why?? It's not going to the `else` part, that's for sure... Any ideas what could cause the body to disappear ? – Misha Moroshko Jul 02 '11 at 04:16
  • What is output to the console if you log `File.size?(path)` ? Is the server seeing it as 0 bytes, perhaps? A permissions error? Just thinking out loud. – d11wtq Jul 02 '11 at 04:19
  • I'm starting to suspect there's a configuration problem between your Rails app and Passenger, but I don't really know much about that, sorry. According the send_file documentation, it uses an HTTP header X-Sendfile, which is interpreted by the server, but something is amiss here. – d11wtq Jul 02 '11 at 05:32
  • @MishaMoroshko let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/1076/discussion-between-d11wtq-and-misha-moroshko) – d11wtq Jul 02 '11 at 05:32
  • Haha, sorry, I didn't know it would just go ahead and create a chat when I clicked that link! – d11wtq Jul 02 '11 at 05:34
  • Thanks for your efforts! I found a solution :) (See my answer) – Misha Moroshko Jul 02 '11 at 09:14