Your SlideShare is downloading. ×
Validações no Ruby on Rails
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Validações no Ruby on Rails

3,155
views

Published on

Breve apresentação sobre algumas validações do Rails no Model

Breve apresentação sobre algumas validações do Rails no Model

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,155
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Validações! http://edgeguides.rubyonrails.org/ active_record_validations.html
  • 2. Validações Rails • Configurações no modelo • Garantem que somente objetos válidos sejam persistidos • Métodos que disparam • create • save • update • update_attributes
  • 3. Obrigatório class Person < ActiveRecord::Base validates :name, presence: true validates_presence_of :idade end
  • 4. Tamanho class Person < ActiveRecord::Base validates :name, length: { minimum: 2 } validates :bio, length: { maximum: 500 } validates :password, length: { in: 6..20 } validates :registration_number, length: { is: 6 } end
  • 5. Tamanho class Essay < ActiveRecord::Base validates :content, length: { minimum: 300, maximum: 400, too_short: "minimo %{count} caracteres", too_long: "maximo %{count} caracteres" } end
  • 6. Numéricos class Player < ActiveRecord::Base validates :points, numericality: true validates :games_played, numericality: { only_integer: true } end
  • 7. Numéricos :greater_than :equal_to :greater_than_or_equal_to :odd :less_than :even :less_than_or_equal_to ! !
  • 8. Unicidade class Account < ActiveRecord::Base validates :email, uniqueness: true end
  • 9. Unicidade class Holiday < ActiveRecord::Base validates :name, uniqueness: { scope: :year, message: "should happen once per year" } end
  • 10. Unicidade class Person < ActiveRecord::Base validates :name, uniqueness: { case_sensitive: false } end