How to append to an XML response an error attribute using Ruby on Rails 3?
Posted
by
user502052
on Stack Overflow
See other posts from Stack Overflow
or by user502052
Published on 2011-01-09T14:48:58Z
Indexed on
2011/01/09
14:53 UTC
Read the original article
Hit count: 234
I am trying to implement REST APIs, so in my RoR3 application I have XML responses. Before to pass to a consumer the XML, I wuold like to check if there are errors and, if so, send back a response with error messages.
I read "Active Record Validations and Callbacks" guides on the RoR website, but it seems not work in my case.
I extract from the database a resource doing
@response = User.find_by_id(1)
and I wuold like, if possible, to add error to it.
Seeing some examples I have seen how to report errors in an XML file
format.xml { render :xml => @response.errors }
but how I can add append new errors to the @response?
Maybe something like this:
errors.add(:password, "is invalid")
© Stack Overflow or respective owner