# ActiveResource and validation errors

**URL:** <https://www.ruby-forum.com/t/activeresource-and-validation-errors/176491>\
**Category:** Rails\
**Created:** [October 1, 2009, 9:40am UTC](https://www.ruby-forum.com/t/activeresource-and-validation-errors/176491 "2009-10-01T09:40:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lathiat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7feea3/32.png) [@lathiat](https://www.ruby-forum.com/u/lathiat)\
**Post date:** [October 1, 2009, 9:40am UTC](https://www.ruby-forum.com/t/activeresource-and-validation-errors/176491/1 "2009-10-01T09:40:11Z")

</div>

Howdy All,

I am trying to implement a fairly simple REST controller which I am  
then interfacing with ActiveResource. The problem I am having is when  
the validation fails, the errors are not being returned to the model  
on the ActiveResource style in a way I can access.

I am running Rails 2.3.4 on both sides of the application. The code I  
have in my controller for the ‘update’ method is as follows:

def update  
@credit\_card = CreditCard.find(params[:id])

```
respond_to do |format|
  if @credit_card.update_attributes(params[:credit_card])
    flash[:notice] = 'CreditCard was successfully updated.'
    format.html { redirect_to(@credit_card) }
    format.xml { head :ok }
  else
    logger.debug(@credit_card.errors.to_xml)
    format.html { render :action => "edit" }
    format.xml { render :xml => @credit_card.errors, :status

```

=\> :unprocessable\_entity }  
end  
end  
end

The most notable part is the “format.xml { render :xml =\>  
@credit\_card.errors, :status =\> :unprocessable\_entity }”.

I checked with the logger.debug the XML is being generated and looks  
reasonable to me. The XML I am seeing is:

\<?xml version="1.0" encoding="UTF-8"?\> Card expiry year must be greater than or equal to 9

I have checked this seems to return OK, what I have noticed is when we  
compare to the ActiveResource documentation, there is no “type=array”  
evident.

ActiveResource::Base example of an error return:  
First cannot be empty

I also found the following bug report;  
[http://dev.rubyonrails.org/ticket/8872](http://dev.rubyonrails.org/ticket/8872)

Which seems to describe this problem (lack of tyoe=array) but has  
stalled and the posted “fix” does not work.

Additionally I tested this by doing a simple return with the example  
code;  
format.xml { render :xml =\> ‘First cannot  
be empty’, :status =\> :unprocessable\_entity }

However my object still shows an empty errors array:  
— &id001 !ruby/object:ActiveResource::Errors  
base: !ruby/object:CreditCard  
attributes:  
  
errors: \*id001  
prefix\_options: {}

errors: {}

Was hoping to be pointed to either an example of someone else doing  
this successfully or some more in depth information on what I’ve done  
wrong. Either is fine!

Appreciate your time.

Best Regards,  
Trent

---

<div class="post-metadata">

**Author:** ![lathiat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7feea3/32.png) [@lathiat](https://www.ruby-forum.com/u/lathiat)\
**Post date:** [October 17, 2009, 8:52pm UTC](https://www.ruby-forum.com/t/activeresource-and-validation-errors/176491/2 "2009-10-17T20:52:47Z")

</div>

i have the exact same problem!  
any solution yet?

---

<div class="post-metadata">

**Author:** ![lathiat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/7feea3/32.png) [@lathiat](https://www.ruby-forum.com/u/lathiat)\
**Post date:** [October 17, 2009, 8:55pm UTC](https://www.ruby-forum.com/t/activeresource-and-validation-errors/176491/3 "2009-10-17T20:55:07Z")

</div>

went back to 2.3.3 from 2.3.4  
works without any problems
