This project is archived and is in readonly mode.

#5038 ✓resolved
Mike Abner

ActiveResource not handling updates correctly

Reported by Mike Abner | July 2nd, 2010 @ 11:08 PM

Docs say that calls to PUT should return an HTTP 204 status with no content. If you follow that then you get an error in ActiveRecord::Base.load_attributes_from_response. "NoMethodError: undefined method strip' for nil:NilClass".

If you use Sinatra and write an API that conforms to the ActiveResource docs, then you should return a 204 status with no body there is no Content-Length header set...and Rack won't let you set one. 'Rack::Lint::LintError: Content-Length header found in 204 response, not allowed'

class Task < ActiveResource::Base
end
t = Task.create(:desc => "do something")
t.desc = "Do the dishes"
t.save!  <-- Errors out with 'NoMethodError: undefined method `strip' for nil:NilClass' because there is no content length header.

The fix is simple.

def load_attributes_from_response(response)
  if !response['Conent-Length'].blank? && response['Content-Length'] != "0" &&
        response.body.strip.size > 0
    load(self.class.format.decode(response.body))
  end
end

For Reference:

http://github.com/rack/rack/blob/master/lib/rack/lint.rb

Line 464: check_content_type

There must be a Content-Type, except when the
Status is 1xx, 204 or 304, in which case there must be none
given.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages