2

I'm a n00b to the paperclip gem, so please excuse me, but I have spent the better part of two hours on this without progress (and I have watched the railscast on it):

My Rails app has a model with a paperclip attachment:

class Foo::Bar < ActiveRecord::Base
  attr_protected  :id
  has_attached_file :mydocument
end

And whenever I try to submit a form with a blank file field for this attachment I get the following error:

Paperclip::AdapterRegistry::NoHandlerError: No handler found for ""

What am I to do? (I installed ImageMagick and specified Paperclip.options[:command_path] = 'C:\Program Files\ImageMagick-6.8.4-Q16' in my environment file, not that I think that should make a difference in this case.)

I've uninstalled and reinstalled paperclip. I've restarted my computer. I ran the app on a co-worker's computer, and didn't get the error. But on my machine, I still get the error.

JellicleCat
  • 28,480
  • 24
  • 109
  • 162
  • Have you run the migration for the `mydocument` attachment on `Foo::Bar`? If you post the backtrace for the `Paperclip::AdapterRegistry::NoHandlerError` exception, I can look at the source code for Paperclip and find out where the error is. – Benjamin Manns Apr 16 '13 at 22:48
  • Very kind. Yes, I did run the migration. Here's my log: http://pastie.org/7621106 – JellicleCat Apr 16 '13 at 22:52
  • Are you running any kind of custom URL structures or anything? Are you running the same database as your coworker? It may be something like a missing `Phone`, `PhoneType`, or `Carrier`. Also, it looks like you're running on Windows. Is your coworker also running Windows? – Benjamin Manns Apr 16 '13 at 23:56
  • We're both on windows. I don't know what you mean by custom URL structures. I haven't specified any non-defaults for `path` or `url` when I declare the paperclip attachment, if that's what you mean. I've tried this same operation on a simpler form (for another model) that also has a paperclip attachment, and I get the same error. – JellicleCat Apr 16 '13 at 23:57

1 Answers1

5

After reading through the Paperclip source, it looks like you are running into an error in the call trace:

Foo::Bar.mydocument = document
# calls
Foo::Bar.attachment_for(:mydocument).assign(document)
# calls
file = Paperclip.io_adapters.for(document)
# calls
handler_for(document).new(document)

And it looks like the handler_for call is failing because target is an empty string or is empty-string-like.

In your controller, try printing the params object to see what is in params[:foo_bar][:mydocument]. That may lead you closer to the root issue. Things that may be the problem could include

  • Different attribute names between controller and view
  • Different attribute names between controller and model
  • A messed up form_tag or form_for that doesn't have the correct encoding set (try :html => {:multipart => true}).
Benjamin Manns
  • 9,028
  • 4
  • 37
  • 48
  • Yes, it's an empty string. But I assume paperclip shouldn't be even trying to handle an empty string because, as indicated above, my app works without error on my coworker's computer. (And, yes, we have raked the migrations.) Apparently there's something wrong with my computer set up. – JellicleCat Apr 17 '13 at 15:10
  • What does the rendered form in the view look like? – Benjamin Manns Apr 17 '13 at 17:57
  • The site isn't live, so I can't direct you to it, but it's a pretty simple form: a few text inputs, a file input. Do you have something in mind when you say 'look like'? – JellicleCat Apr 17 '13 at 18:21
  • What is the HTML that is outputted? – Benjamin Manns Apr 17 '13 at 19:24
  • Here's the pastie: http://pastie.org/private/ojbk16hdnhq5is2y4ecpdq – JellicleCat Apr 17 '13 at 19:32
  • It looks like your attachment is in a nested form for `Profile` under the `ContactInfo` model. Do you have `accepts_nested_attributes_for :profile` in your `ContactInfo` model? It also looks like you're using Ajax to submit this form with Remotipart to handle the file upload part. If you convert the form to a non-Ajax request, does it work? – Benjamin Manns Apr 17 '13 at 20:00
  • Oddly, using a synchronous request **does** prevent the error. I can't guess why or what to do about it. (Yes, I have `accepts_nested_attributes_for :profile` and `attr_accessible :profile_attributes`. I have it working on two other machines.) – JellicleCat Apr 17 '13 at 20:34
  • 1
    I faced the error because of a missing multipart: true option in my form_tag.Thanks @benjamin-manns. – Jignesh Gohel Oct 02 '13 at 10:53