Topic: validation on user model

Hi, I wonder how I can do validation on my user model.

class User < ActiveRecord::Base

  attr_accessor :password, :conf_password, :email_confirmation
  attr_accessible :fname, :lname, :email, :hashed_password
  validates_uniqueness_of :email
  validates_presence_of  :email, :hashed_password
  validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/

before creating a user, I want to make sure that password, conf_password and email, email_confirmation are matched.

There's no password, conf_password, email_confirmation field in my mysql table.

I am wondering where I should do the validation on confirming passwords and emails.


Re: validation on user model

You would do the validates_confirmation_of validation.

class User < ActiveRecord::Base
  validates_confirmation_of :password

Is this not working?

Just make sure to stick with the naming described in the documentation

Railscasts - Free Ruby on Rails Screencasts

Re: validation on user model

that works.