Search code examples
ruby-on-railsrubywebrick

Rails development server status header is symbol


I'm having an issue with the Rails development server where it will successfully process a request, but then crash and return no data. Chrome shows a No Data Received page, and other browsers show the equivalent. In the console I see something like:

  Rendered layouts/_confirm_nag.html.erb (0.2ms)
  Rendered layouts/_modals.html.erb (0.0ms)
Completed 200 OK in 1219ms (Views: 26.8ms | ActiveRecord: 90.5ms)
[2014-09-17 14:32:45] ERROR NoMethodError: undefined method `gsub' for :status:Symbol
    /Users/jaime/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpresponse.rb:288:in `block in send_header'
    /Users/jaime/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpresponse.rb:287:in `each'
    /Users/jaime/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpresponse.rb:287:in `send_header'
    /Users/jaime/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpresponse.rb:207:in `send_response'
    /Users/jaime/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:110:in `run'
    /Users/jaime/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

Strangely enough, I only see this on one particular request, every other page works perfectly fine.


Solution

  • When I put a byebug in httpresponse.rb I saw:

    (byebug) @header
    {"x-frame-options"=>"SAMEORIGIN", "x-xss-protection"=>"1; mode=block","x-content-type-options"=>"nosniff", 
    :status=>"Error", :message=>"Subtotal can't be blank, Subtotal is not a number, Shipping cost can't be blank, Shipping cost is not a number, Processing fee can't be blank, Processing fee is not a number, Tax can't be blank, Tax is not a number, Total can't be blank, Total is not a number", 
    "content-type"=>"text/html; charset=utf-8", "etag"=>"\"b589f2660cd40fecdac593916c837f67\"", "cache-control"=>"max-age=0, private, must-revalidate", "x-request-id"=>"6075ecb6-5f9f-4243-b600-f934a1f436fd", "x-runtime"=>"6.469675", "server"=>"WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)", "date"=>"Wed, 17 Sep 2014 18:47:26 GMT", "content-length"=>14914, "connection"=>"Keep-Alive"}
    

    By those error messages, I was able to track it to this block:

    # Check if the transaction saved
    if @transaction.errors.any?
        response[:status] = 'Error'
        response[:message] = @transaction.errors.full_messages.join(', ')
        return response
    end
    

    The issue here was that I was trying to use a hash named response without defining it, so instead I ended up messing with a global variable.