sybohy
sybohy

Reputation: 1876

Devise Error Message Gender Custom

I started working with Devise. Quite an awesome gem. Reading through a neat exchange I was able to do a lot of interesting message customization.

NOW though, I'm running into an intriguing issue with customizing error messages based on noun gender for I18N purposes. Here, I have an error message containing %{resource}, where resource will sub in my model name (user). In French, the word coming before the %{resource} will vary depending on gender. Is there a way for me to branch out to a particular error message based on the %{resource} gender?

Upvotes: 1

Views: 509

Answers (1)

M. Cypher
M. Cypher

Reputation: 7066

You can customize the human-readable model name by implementing the model_name instance method in your user model.

http://api.rubyonrails.org/classes/ActiveModel/Naming.html

The model_name method has to return an object of type ActiveModel::Name

http://api.rubyonrails.org/classes/ActiveModel/Name.html

You can customize this object to fit your i18n needs.

Upvotes: 1

Related Questions