This project is archived and is in readonly mode.

#3386 ✓duplicate
Vanne

ActiveResource not picking up (validation) errors in 2.3.4

Reported by Vanne | October 17th, 2009 @ 08:16 PM

on the server side (2.3.4 app using ActiveRecord models:

  format.xml  { render :xml => @participant.errors, :status => :unprocessable_entity }

received on client side (2.3.4 app using ActiveResource models)

  HTTP/1.1 422
Connection: close Content-Type: application/xml; charset=utf-8 Date: Sat, 17 Oct 2009 18:11:16 GMT Server: WEBrick/1.3.1 (Ruby/1.8.7/2008-08-11) X-Runtime: 11 Content-Length: 101 Cache-Control: no-cache <?xml version="1.0" encoding="UTF-8"?> <errors> <error>Username cannot be empty!</error> </errors>

@participant.save does return false but there are no errors available!

Went back to 2.3.3 on client side and all works well.

See also http://groups.google.com/group/rubyonrails-talk/browse_thread/threa...

Comments and changes to this ticket

  • James Brennan

    James Brennan October 23rd, 2009 @ 11:18 PM

    I'm seeing the same error. It's very possible that this is being caused by the case/when block starting on line 262 of validations.rb

          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
    

    I'm about to write a patch, unless someone else has already done it?

  • James Brennan

    James Brennan October 23rd, 2009 @ 11:19 PM

    My last post wasn't entirely clear. I'm seeing it fail when the error.response['Content-Type'] = "application/xml; charset=utf-8"

  • Łukasz Pinkosz

    Łukasz Pinkosz November 3rd, 2009 @ 12:46 PM

    I also came across this issue.
    When I call this on my remote service:

        render :xml => @my_object.errors, :status => :unprocessable_entity
    
    render returns following content-type in response header:
    "application/xml; charset=utf-8"
    
    That obviously won't match line 263 of validations.rb. So I changed the case block to:
          case error.response['Content-Type']

      when /application\/xml/
        errors.from_xml(error.response.body)
      when /application\/json/
        errors.from_json(error.response.body)
      end</code>
    
    
    
    
    And now works as expected.
  • JackC
  • Jeremy Kemper

    Jeremy Kemper January 19th, 2010 @ 06:42 PM

    • State changed from “new” to “duplicate”

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

Referenced by

Pages