Wow - RoR blew my mind for the n'th time. What a framework. I love it!
So, user.errors
is just an ActiveModel::Errors
object. Some errors are, as far as I understand, specified in the locale in the Devise gem. Others, like uniqueness of indexed fields etc. (like the email field), are provided by ActiveModel-validation. That's why I couldn't find the given error in the gem locale.
Now; the ActiveModel::Errors
documentation has something pretty interesting to say. It says that there is a method, named full_messages()
, that "returns all the full error messages in an array". My controller now looks like this:
if user.save
render :json => user.as_json, :status => 201
else
warden.custom_failure!
render :json => { :messages => player.errors.full_messages }, :status => 422
end
That's it.