Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveResource doesn't parse validations when extended content type

#3157

For some (unknown) reasons the content type of the response is "application/xml; charset=utf-8" instead of plain 'application/xml' in my setup. In this case ActiveResource::Validations#save_with_validation doesn't parse the included errors, because that method performs a strict checkn on 'application/xml'

Reported by Christian Seiler · September 7th, 2009 @ 02:40 PM

State: resolved
Milestone: 2.3.6
Assigned to: nobody
Importance: none

Activity

  1. Jake Scruggs
    Jake Scruggs

    I've also had problems with this when using Rails 2.3.4 to consume a resource from a Rails 2.1.1 app. I believe this can be fixed by changing validations.rb in the ActiveResource(2.3.4) gem starting with line 258:

        def save_with_validation
          save_without_validation
          true
        rescue ResourceInvalid => error
          case error.response['Content-Type']
          when /application\/xml/
            errors.from_xml(error.response.body)
          when /application\/json/
            errors.from_json(error.response.body)
          end
          false
        end
    

    In the above lines I've changed the case statement to use regex instead of doing a strict string match.

    Any reader of this ticket who wants to fix their own app can use this monkey patch:

    module ActiveResource
      # Errors returned from the API layer were not getting put into our User object as of Rails 2.3.4
      class Base
        def save
          save_without_validation
          true
        rescue ResourceInvalid => error
          case error.response['Content-Type']
          when /application\/xml/
            errors.from_xml(error.response.body)
          when /application\/json/
            errors.from_json(error.response.body)
          end
          false
        end
      end
    end
    

    September 10th, 2009 @ 10:28 PM

  2. CancelProfileIsBroken
  3. Rizwan Reza
    Rizwan Reza
    • State changed from new to resolved
    • Tag changed from bugmash to activeresource
    • Milestone set to 2.3.6

    This has been resolved in the 2-3-stable.

    January 21st, 2010 @ 06:54 AM

  4. Jatinder Singh
  5. Rizwan Reza