2

I am using Devise in my Rails app and I wonder why it downcases all my model names in its error messages: Source code on Github

Is there any way to override this?

In German, for example, nouns start with capital letters, e.g. "Benutzer" is correct, but "benutzer" is wrong.

I have this in my devise.de.yml:

de:

  activerecord:
    models:
      user: "Benutzer"

However, Devise still renders Benutzer in small letters:

Konnte benutzer nicht speichern

This is wrong!

How can I fix this?

Thanks for any help...

Tintin81
  • 9,821
  • 20
  • 85
  • 178

2 Answers2

2

Quick fix

Add a file app/helpers/devise_helper.rb with the following contents:

module DeviseHelper
  def devise_error_messages!
    return "" if resource.errors.empty?

    messages = resource.errors.full_messages.map { |msg| content_tag(:li, msg) }.join
    sentence = I18n.t("errors.messages.not_saved",
                      :count => resource.errors.count,
                      :resource => resource.class.model_name.human)

    html = <<-HTML
    <div id="error_explanation">
      <h2>#{sentence}</h2>
      <ul>#{messages}</ul>
    </div>
    HTML

    html.html_safe
  end
end

:resource was forced to downcase before my edit:

resource.class.model_name.human.downcase

Source adapted from https://github.com/plataformatec/devise/blob/master/app/helpers/devise_helper.rb

Patrick Oscity
  • 53,604
  • 17
  • 144
  • 168
0

I think that you will have to overwrite the devise's method devise_error_messages! in a helper and put your logic there (remove the downcase or create cases per locales if you want downcase for other than German locale).

Lazarus Lazaridis
  • 5,803
  • 2
  • 21
  • 35