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!

+3
api ruby-on-rails devise


source to share


No one has answered this question yet

Check out similar questions:

1023
How do I get the current absolute url in Ruby on Rails?
659
Error on getting: Peer authentication failed for user "postgres" when trying to get pgsql to work with rails
385
Rails I18n validation warning warning
249
Fully customizable validation error message with Rails
85
Don't develop a secret key
3
Devise sign up by email or mobile
1
How to get user id from my database - rails
0
Getting "I18n :: InvalidLocale" "ko" is not a valid locale error when ko.yml is present and in the correct directory
0
Add key translation to Devise locale.yml file
0
rails design custom responses when using i18n



All Articles
Loading...
X
Show
Funny
Dev
Pics