Skip to content

Instantly share code, notes, and snippets.

@KenneyE
Created April 26, 2014 23:57
Show Gist options
  • Save KenneyE/11334255 to your computer and use it in GitHub Desktop.
Save KenneyE/11334255 to your computer and use it in GitHub Desktop.
This is the validation of a new user with a basic auth system
class User < ActiveRecord::Base
attr_reader :password
before_validation :ensure_token
validates :username, uniqueness: true
validates :username, :session_token, presence: true
validates :password, presence: true, on: :create
validates :password_digest, presence: { message: "Password can't be blank"}
validates :password, length: { minimum: 6, allow_nil: true }
#...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment