This project is archived and is in readonly mode.
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
-
Mike Abner July 7th, 2010 @ 10:28 PM
- Tag changed from undefined method 'strip, activeresource, load_attributes_from_response, update to undefined method 'strip, activeresource, load_attributes_from_response, patch, update
-
José Valim July 9th, 2010 @ 06:13 PM
- Assigned user set to José Valim
- Importance changed from to Low
-
José Valim July 13th, 2010 @ 07:11 AM
Could you please add a test to your patch to ensure we won't have regressions in the future? Thanks!
-
Neeraj Singh September 8th, 2010 @ 06:58 PM
- State changed from incomplete to open
Attached is a failing test. I mean it fails without the patch :-)
-
Repository September 18th, 2010 @ 07:50 PM
- State changed from open to resolved
(from [154081f0f74988bdb8979f0447ff5816ab83d8fd]) make sure a Content-Length header exists and that the response.body is not nil before trying to call methods on it. Rack does not allow HTTP 204 responses to have a content-length header set. [#5038 state:resolved] http://github.com/rails/rails/commit/154081f0f74988bdb8979f0447ff58...
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>
People watching this ticket
Attachments
Referenced by
- 5038 ActiveResource not handling updates correctly (from [154081f0f74988bdb8979f0447ff5816ab83d8fd]) make su...