Skip to content

Instantly share code, notes, and snippets.

@borisd
Created January 15, 2014 16:35
Show Gist options
  • Save borisd/8439500 to your computer and use it in GitHub Desktop.
Save borisd/8439500 to your computer and use it in GitHub Desktop.
Solutions to Validations
# Validate AGE is above 16
# Validate First Name is longer than 5 characters
# Validate Username is unique
class User < ActiveRecord::Base
attr_accessible(:age, :first_name, :last_name, :username)
validates :age, numericality: { greater_than: 16 }
validates :first_name, length: { minimum: 5 }
validates :username, uniqueness: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment