mercredi 22 avril 2015

Override validations of gem devise

In my model user I add the following validations The problem is that devise have implemented its own validations. How can I override the validations of Devise

user.rb

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable, :lockable and :timeoutable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
  validates_presence_of :email, :message=>"email no puede estar vacio"
  validates_presence_of :password, :message=>"password no puede estar vacio"
  validates_presence_of :password_confirmation,:message=>"validate confirmation no puede estar vacio"
  end

Browser

Email can't be blank  #validation of devise
Email email no puede estar vacio #my own validation
Password can't be blank #validation of devise
Password password no puede estar vacio #my own validation
Password confirmation validate confirmation no puede estar vacio

Other problem that I have is that rails shows the name of attribute before of the customized message

Email email no puede estar vacio #my own validation #wrong
email no puede estar vacio #well

Aucun commentaire:

Enregistrer un commentaire