Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the default error message with simple_form

I don't manage to change the default error message from simple form, i tried to edit the simple form locale file but it seems to be ignored

Here is my locale file :

#config/locales/simple_form.en.yml
en:
  simple_form:
    error_notification:
      default_message: "A custom message:"

But i still get "Please review the problems below:"

Does anybody knows what i'm doing wrong ?

like image 389
vdaubry Avatar asked Mar 10 '13 22:03

vdaubry


1 Answers

Change your :default_message to :your_model_name

As you can see in the source, error_notification method uses translate_error_notification to get translation from YAML file.

def translate_error_notification
  lookups = []
  lookups << :"#{object_name}"
  lookups << :default_message
  lookups << "Please review the problems below:"
  I18n.t(lookups.shift, scope: :"simple_form.error_notification", default: lookups)
end

For user model lookups contains:

lookups == [:user, :default_messge, "Please review the problems below:] 

Translation could be differrent for each object so this transaction is called:

#config/locales/simple_form.en.yml
en:
  simple_form:
    error_notification:
      user: "A custom message:"

Vote if it'll help ;)

like image 62
swilgosz Avatar answered Nov 06 '22 14:11

swilgosz