Learn Geek languages like Big data,Hadoop,Hive,Pig,Sqoop ,flume,Cassandra,Hbase,Ruby On Rails,Python,Java and many more.

Wednesday 13 July 2016

Validation in Rails


class Person < ApplicationRecord
  validates :name, presence: true
end

 OR

class Person < ApplicationRecord
  validates :name, :login, :email, presence: true
end

class Person < ApplicationRecord
  validates :terms_of_service, acceptance: true
end

class Person < ApplicationRecord
  validates :email, confirmation: true
end

class Product < ApplicationRecord
  validates :legacy_code, format: { with: /\A[a-zA-Z]+\z/,
    message: "only allows letters" }
OR a-z,A-Z,0-9
end

class Person < ApplicationRecord
  validates :name, length: { minimum: 2 }
  validates :bio, length: { maximum: 500 }
  validates :password, length: { in: 6..20 }
  validates :registration_number, length: { is: 6 }
end

class Player < ApplicationRecord
  validates :points, numericality: true
end

class Account < ApplicationRecord
  validates :email, uniqueness: true
end

No comments:

Post a Comment

if you have any query regarding geek languages,
email on arora.ratul@gmail.com