Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

"can't convert nil into Hash" when submitting a multipart form #13

Closed
thijsc opened this issue Apr 14, 2011 · 21 comments
Closed

"can't convert nil into Hash" when submitting a multipart form #13

thijsc opened this issue Apr 14, 2011 · 21 comments

Comments

@thijsc
Copy link

thijsc commented Apr 14, 2011

When I try to post any multipart form in the app, webrick crashes:

Internal Server Error

can't convert nil into Hash
WEBrick/1.3.1 (Ruby/1.8.7/2009-06-12) at 127.0.0.1:49999

I'm having trouble finding any more info in any of the logs.

@thijsc
Copy link
Author

thijsc commented Apr 17, 2011

Are other people seeing this too when posting multipart forms? I'm curious if it's something specific to my setup which I could debug.

@thijsc thijsc closed this as completed Apr 17, 2011
@thijsc thijsc reopened this Apr 17, 2011
@metaskills
Copy link

I got this area too today. Seems if the form does not have an attachment, it will bomb.

@jens
Copy link

jens commented May 23, 2011

Got this as well...

@j16r
Copy link
Contributor

j16r commented May 27, 2011

Had a look at this one myself, we get an error, slightly different though:

Internal Server Error

bad content body
WEBrick/1.3.1 (Ruby/1.8.7/2011-02-18) at 127.0.0.1:56925

Looked through the webkit_server cpp code, and couldn't see where it might be a problem, thought maybe it was linkDelegationPolicy handling but no luck there.

@fxposter
Copy link

fxposter commented Jun 7, 2011

Got the same error. Turns out that rack is raising:

EOFError: bad content body

right here: https://github.com/rack/rack/blob/master/lib/rack/request.rb#L182

unless @env["rack.request.form_hash"] = parse_multipart(env)

on the next request after submitting multipart form.

@reedlaw
Copy link

reedlaw commented Jun 22, 2011

I'm having the same issue with same error as fxposter (bad content body). Any workarounds for this?

@metaskills
Copy link

I have done this in my forms view code (HAML). A bit hacky, but it works.

:html => { :multipart => !Rails.env.test? }

@reedlaw
Copy link

reedlaw commented Jun 22, 2011

Unfortunately that will not test the use of the form to submit attachments.

@fxposter
Copy link

@metaskills this is definitely not an option.

@kilaulena
Copy link

Same problem here. Any hints to workarounds appreciated.

@thijsc
Copy link
Author

thijsc commented Jul 20, 2011

Any progress here? This is really the only thing holding us back on using this great gem.

I'd love to help out myself, but I have no idea how to go about debugging this.

@ebeigarts
Copy link

Same here. The form gets submitted, but the redirect (the next GET request) fails with "Unable to load URL", if I turn off multipart forms, it works.

@melcher
Copy link

melcher commented Aug 19, 2011

Getting the same issue as @excepttheweasel. Looking for a work-around... anyone have progress here?

Internal Server Error

bad content body
WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18) at 127.0.0.1:56993

@ebeigarts
Copy link

This worked for me:

# config/environments/test.rb

class CapybaraWebkitFixer
  def initialize(app)
    @app = app
  end

  def call(env)
    if env['REQUEST_METHOD'] == "GET" && env['CONTENT_TYPE'] && env['CONTENT_TYPE'] =~ /^multipart/
      env['CONTENT_TYPE'] = nil
    end
    @app.call(env)
  end
end

Rails.application.config.middleware.insert_after Rack::Runtime, CapybaraWebkitFixer

@jfelchner
Copy link

+1 I'm getting the same error when submitting a multi-part form w/o any file attachments.

Internal Server Error
can't convert nil into Hash
WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)

@rud
Copy link

rud commented Sep 11, 2011

@ebeigarts: that hack fixes the behavior for me too. I have this problem with a Rails 3.1.0 app on ruby 1.9.2p312 (2011-08-11 revision 32926) [x86_64-darwin11.1.0].

A few debugging hints for capybara-webkit..

Show server debug output:
lib/capybara.rb in the gem: set Thin::Logging.silent = false in run_default_server to see this error.

Enable a lot of client debug output:
Use: Capybara.javascript_driver = :webkit_debug
instead of
Capybara.javascript_driver = :webkit

This shows the wire-protocol for the webkit driver, which may come in handy.

@ebeigarts
Copy link

This has been fixed in #162

@rud
Copy link

rud commented Sep 16, 2011

Works like a charm, thank you @ebeigarts! :)

@jedeleh
Copy link

jedeleh commented Sep 21, 2011

When will this be available for a general "gem install"?

@thijsc
Copy link
Author

thijsc commented Sep 25, 2011

A new version of the gem with this fix would indeed be great.

@jferris
Copy link
Member

jferris commented Oct 1, 2011

A gem was released with this fix a while ago.

@jferris jferris closed this as completed Oct 1, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests