This project is archived and is in readonly mode.

#3157 ✓resolved
Christian Seiler

ActiveResource doesn't parse validations when extended content type

Reported by Christian Seiler | September 7th, 2009 @ 02:40 PM | in 2.3.6

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'

Comments and changes to this ticket

  • Jake Scruggs

    Jake Scruggs September 10th, 2009 @ 10:28 PM

    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
    
  • CancelProfileIsBroken
  • Rizwan Reza

    Rizwan Reza January 21st, 2010 @ 06:54 AM

    • 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.

  • Jatinder Singh
  • Rizwan Reza

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

Pages