16

I am using the authlogic gem for user validation on one of my sites. All is going well, but I am wondering if it's possible to change the error message that gets returned when the user types in an invalid email address.

Thanks!

bloudermilk
  • 17,820
  • 15
  • 68
  • 98

3 Answers3

16

authlogic has a special setting for this purpose:

class UserSession < Authlogic::Session::Base  
  generalize_credentials_error_messages true
end

The error message will be the same: "Email/Password combination is not valid", whether the password or email is bad. You can change the text of the message specifying a string instead of true:

generalize_credentials_error_messages "Try again"
Braulio Carreno
  • 421
  • 2
  • 7
14

You can override the settings for email validation with validates_format_of_email_field_options. However, if you only want to change the message you can merge options with merge_validates_format_of_email_field_options so that only the options you specify are overridden. You specify settings in your User controller like so:

class User < ActiveRecord::Base
    acts_as_authentic do |c|
        c.merge_validates_format_of_email_field_options :message => 'My message'
    end
end

You can also change the settings for length and uniqueness validations. There are also a lot more other settings, take a look at the documentation, in the ::Config sections of each module you can find settings and their default values and how to override them.

Alternatively you can use localization and set error_messages.email_invalid (that's what the plugin looks for before setting it to the default English sentence, also useful if you are building an international application).

Janteh
  • 398
  • 2
  • 6
4

Override Authlogic error messages by changing in en.yml file
It works for me.

en:
  authlogic:
      error_messages:
         login_blank: "Please enter the email address."
         login_not_found: "This email address is already in the system. Please choose a different email address."
         login_invalid: "Please enter a valid email address."
Anuj
  • 1,737
  • 3
  • 16
  • 29