How to append to an XML response an error attribute using Ruby on Rails 3?
- by user502052
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")