views:

261

answers:

2

I have a very simple controller set up:

class LibrariesController < ApplicationController

...

  def create
    @user.libraries << Library.new(params)
    @user.save
    render :json => "success!"
  end

...

end

Basically, whenever I try to access the create method of LibrariesController using HTTParty.post I get a WEBrick::HTTPStatus::LengthRequired error on the server. The method is not even being accessed! Here is the stack trace (this is the full output server side - notice that the controller isn't even being accessed):

[2010-04-16 00:35:39] ERROR WEBrick::HTTPStatus::LengthRequired
[2010-04-16 00:35:39] ERROR HTTPRequest#fixup: WEBrick::HTTPStatus::LengthRequired occured.
[2010-04-16 00:35:39] ERROR NoMethodError: private method `gsub!' called for #<Class:0x2362160>
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/1.8/webrick/htmlutils.rb:17:in `escape'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/1.8/webrick/httpresponse.rb:232:in `set_error'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/1.8/webrick/httpserver.rb:70:in `run'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/webrick.rb:14:in `run'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:111
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    /usr/local/Cellar/ruby_187/1.8.7-p249/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3

I'm running rails 2.3.5 and ruby 1.8.7. Any help would be greatly appreciated. Let me know if you need more details.

+1  A: 

I don't know if this is still relevant for Webrick or if that has been fixed but there is a know issue for the error you are getting Read line 2 on this TODO page on RubyForge

Have you tried gem install mongrel and running it with mongrel or other ruby server?

Nick Gorbikoff
This is true - however, this message was written in 2008 and it also says that this error is "low priority." I wonder if I've configured something wrong...When I run with Mongrel I get the following error:ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken): Rendered rescues/_trace (178.6ms)Rendered rescues/_request_and_response (1.5ms)Rendering rescues/layout (unprocessable_entity)Hmmmmmm...
Chris Bisignani
Yeah you are right Chris, but that's the only plausible explanation I could wind for an error. However Mongrel error is less cryptic, I've seen a similar issue recently, when I was was working with sessions. What is your session store? and do you have session key and secret setup?
Nick Gorbikoff
A: 

I got this when I did a POST with an empty body. I was using curl.

Something like:

curl -X POST http://url/

I added -d '' and it cleared up the issue.

curl -X POST http://url/ -d ''

In your case, you probably need to add some content to a :body => '' attribute in HTTParty.post

Swards