ActiveResource and validation errors

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 }
    format.html { render :action => "edit" }
    format.xml  { render :xml => @credit_card.errors, :status

=> :unprocessable_entity }

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”

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

I also found the following bug report;

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

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,

i have the exact same problem!
any solution yet?

went back to 2.3.3 from 2.3.4
works without any problems

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs