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 not picking up (validation) errors in 2.3.4

#3386

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

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

State: duplicate
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. James Brennan
    James Brennan

    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?

    October 23rd, 2009 @ 11:18 PM

  2. James Brennan
    James Brennan

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

    October 23rd, 2009 @ 11:19 PM

  3. Łukasz Pinkosz
    Łukasz Pinkosz

    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.

    November 3rd, 2009 @ 12:46 PM

  4. JackC
  5. Jeremy Kemper