Topic: upload_column and Dreamhost

I am trying to use the upload_column plugin on a Rails application hosted on Dreamhost.  I can upload an image just fine and it gets placed in the right folder.  When I try to display the image I get the correct link for it but I get no image on the screen.  I tried changing my permissions to 755, but I still get nothing.  This is the error in the Rails log:

ActionController::RoutingError (no route found to match "/staffer/picture/3/bmwm309_01.jpg" with {:method=>:get}):
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/routing.rb:1292:in `recognize_path'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.2/lib/action_controller/routing.rb:1282:in `recognize'
    /usr/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/dispatcher.rb:40:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi_handler.rb:168:in `process_request'
    /usr/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi_handler.rb:143:in `process_each_request!'
    /usr/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi_handler.rb:109:in `with_signal_handler'
    /usr/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi_handler.rb:142:in `process_each_request!'
    /usr/lib/ruby/1.8/fcgi.rb:600:in `each_cgi'
    /usr/lib/ruby/1.8/fcgi.rb:597:in `each'
    /usr/lib/ruby/1.8/fcgi.rb:597:in `each_cgi'
    /usr/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi_handler.rb:141:in `process_each_request!'
    /usr/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi_handler.rb:55:in `process!'
    /usr/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/fcgi_handler.rb:25:in `process!'

Any help would be much appreciated.

Re: upload_column and Dreamhost

When you navigate in your browser directly to the image what happens?

Are you certain that yourapp/public/staffer/picture/3/bmwm309_01.jpg exists?

I've had problems with permissions on this kind of thing before.  Make sure not only the file but all the directories above it are properly permissioned (chmod -R 776 public/staffer)

Let us know if this doesn't work out still.

Re: upload_column and Dreamhost

If I try to navigate directly to an image I get the following response:

URL: … /moose.gif

no route found to match "/staffer/picture/13/moose.gif" with {:method=>:get}

I noticed that after I upload an image if I tell htaccess to not interrupt the URL's for that folder, like you do with the javascripts and stylesheets folder, the image will display.  But you can no longer upload files into that directory using file column.

I changed the permissions on all the necessary folders, but I still get the same routing error.

I figured out a way to image display where the link in the image tag is actually to an action in the controller.  This action reads the binary data from the image then uses send_data to return the binary data of the file.  I am not sure what sort of performance hit this could cause though.

Last edited by criscokidcmg (2007-04-17 12:29:40)

Re: upload_column and Dreamhost

It's actually quite a performance hit.  Serving static files is cheap and easy but loading the Rails framework and processing through the binary data is really expensive.

Is there a way you can put these images in a different places than the ones uploaded via file_column?  Or some way to distinguish between the two in the .htaccess file?

Re: upload_column and Dreamhost

I wrote some custom code to solve my problem.  I figured I would share it incase someone else needs it.

In my model I now have:

  def uploaded_picture=(picture_field)
    self.picture = picture_field.original_filename"#{RAILS_ROOT}/public/staffer/" + picture_field.original_filename, "wb") {|f| f.write(}
    File.move("#{RAILS_ROOT}/public/staffer/" + picture_field.original_filename, "#{RAILS_ROOT}/public/staff_pictures/"+picture_field.original_filename)
  def get_picture_path
    "/staff_pictures/" + self.picture
  def before_destroy
    File.rm_f("#{RAILS_ROOT}/public/staff_pictures/" + self.picture)

So it writes to a directory that Rails can access, but then moves it to another directory that isn't interrupted.

To get the image back I simply do this in my view.

<img src="<%= staffer.get_picture_path %>">

The form for the upload looks like this:

<p><label for="staffer_picture">Picture</label><br/>
<%=file_field 'staffer', 'uploaded_picture'%></p>

Finally in my .htaccess I have:

RewriteCond %{REQUEST_URI} ^/staff_pictures.*
RewriteRule .* - [L]