Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override validation error message for SecurePassword [duplicate]

Possible Duplicate:
Fully custom validation error message with Rails

I'm playing around with Rails 3.1rc1 and think SecurePassword will be useful for me. But, I don't like the default error message, Password digest can't be blank. If I called validates_presence_of :password_digest myself I could pass :message => "Password can't be blank" but because it's in the framework I'm not sure how to override the message to remove the word "digest" which will only confuse joe user. Anyone know how to do this?

Edit:

Tried adding an 'overriding': validates_presence_of like so:

class User < ActiveRecord::Base
  attr_accessible :email, :password

  has_secure_password
  validates_presence_of :password_digest, :message => "Password can't be blank"
end

But when trying to submit a blank password you just get double the errors:

Form is invalid

  • Password digest can't be blank
  • Password digest Password can't be blank
like image 810
Meltemi Avatar asked May 27 '11 23:05

Meltemi


1 Answers

I believe you can use the Rails Internationalization API to change this.

In your config/locales/en.yml file, add the following:

en:
  activerecord:
    attributes:
      user:
        password_digest: "Password"

If your model class is something other than 'user', you'll need to change that line appropriately.

Anyway, this works for me.

like image 180
bloomdido Avatar answered Nov 28 '22 09:11

bloomdido