Ticket #111 (closed defect: fixed)

Opened 2 years ago

Last modified 15 months ago

NoMethodError when doing Ajax.Request with webrick

Reported by: macournoyer Owned by: somebody
Priority: major Milestone:
Component: camping.rb Version:
Keywords: Cc:

Description

I'm using prototype 1.4.0 and trying to do a simple Ajax request with webrick. (It's working with mongrel)

with the following code on the view side:

url = "/links/#{link.title.encode}/vote/#{verdict}"
a verdict, :onclick => "new Ajax.Request('#{url}', { method: 'post' });",
               :href => 'javascript:void(0);'

I get this response with webrick

Camping Problem!

Linkr::Controllers::Votes.POST

NoMethodError undefined method `read' for nil:NilClass:

  • (eval):24:in `initialize'
  • (eval):44:in `run'
  • /usr/local/lib/ruby/gems/1.8/gems/camping-1.5.177/lib/camping/reloader.rb:117:in `run'
  • /usr/local/lib/ruby/gems/1.8/gems/camping-1.5.177/lib/camping/webrick.rb:45:in `service'
  • /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  • /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  • /usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  • /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  • /usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start'
  • /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start'
  • /usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start'
  • /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
  • /usr/local/lib/ruby/gems/1.8/gems/camping-1.5.177/bin/camping:244
  • /usr/local/bin/camping:18

Change History

Changed 20 months ago by mfredrickson

I can recreate this problem in a non-AJAX context. It seems that some forms cause this problem. Here is an example form that breaks camping's brain:

      form :action => R(Other), :method => 'post' do
          input :type => 'hidden', :value => "kills nil error?"
          input :type => 'submit', :value => "A button"
          input :type => 'submit', :value => "Another buttons"
      end

Adding a simple textfield to the form fixes the problem:

      form :action => R(Other), :method => 'post' do
          label 'Username', :for => 'username'; br
          input :name => 'username', :type => 'text'; br
          input :type => 'hidden', :value => "kills nil error?"
          input :type => 'submit', :value => "A button"
          input :type => 'submit', :value => "Another button"
      end

Changed 15 months ago by zimbatm

  • status changed from new to closed
  • resolution set to fixed

Okay, changeset [201] should do the trick. The problem was sending POST with no body AND "application/x-www-form-urlencoded" content-type. (See, the first form has no named input)

Note: See TracTickets for help on using tickets.