Rails: get validation key instead of i18n string
I am developing a Ruby on Rails 4.1.0 application that has a mobile client API and a backend for a different type of user. The API allows the mobile client to register a user, but I can't get the correct data, so in this case I need to tell the mobile client where the errors were. I am using application 3.2.4 for user management. So right now, if the mobile user wants to sign up and does not perform validations, this is the JSON I am returning to the mobile client:
{"errors": [
"email": ["is not valid"]
]}
Since the mobile app will be multilingual, the app developers will ask me to return all errors with a key instead of a suggestion, so I have to return them something like:
{"errors": [
"email": ["invalid"]
]}
But I cannot find a way to do this easily. When I run user.valid?
, the object user.errors
gets populated with i18n validation errors, so I can't get their keys.
I tried to create an i18n backend (inherit from I18n::Backend::Simple
and overwrite method translate
), but I'm having problems with parameters default
that I don't want to handle when sending confirmation emails, or resetting password instructions emails.
So, I want to know why my entry is invalid, but without the i18n line, only the key. Any idea on how to do this?
Thank!
source to share
No one has answered this question yet
Check out similar questions: