This project is archived and is in readonly mode.

#3650 ✓committed
Christian Seiler

ActiveResource validations throws exceptions if errors missing

Reported by Christian Seiler | January 4th, 2010 @ 05:30 PM | in 3.0.2

If the JSON response lacks the 'errors' element, a nil exception is thrown:

undefined method each' for nil:NilClass /usr/lib/ruby/gems/1.8/gems/activeresource-2.3.5/lib/active_resource/validations.rb:206:infrom_array'

This happens in my case because the resource controller does not render :json => @user.errors. You could say it should, but still I think Rails should be more robust in this case.

Monkeypatch in my project:
module ActiveResource

class Errors
  def from_json(json)
    array = ActiveSupport::JSON.decode(json)['errors'] rescue []
    array ||= []      # THIS IS THE PATCH
    from_array array
  end
end

end

Same applies to XML (probably).

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>

Attachments

Referenced by

Pages