Skip to content

Instantly share code, notes, and snippets.

@borisd
Last active January 3, 2016 05:19
Show Gist options
  • Save borisd/8415093 to your computer and use it in GitHub Desktop.
Save borisd/8415093 to your computer and use it in GitHub Desktop.
Homework lesson #3

Learn !

Its very important to know Validations and Field types as we will use them alot in our code. Please take the time to read (or at least skim over) the validations list to see what kind of validations are possible.

Create a new model

  • Cat with fields "name - string", "breed - string", "birthdate - date"
  • You can use a short hand of model creation like: rails generate model cat name:string height:integer ...

Make sure you can create it from command line via initiator

Cat.create!(:name => 'Suzi', :breed => :angora, birthdate: 3.years.ago)
Remember attr_accessible !

Add validations

  1. Name must be present and between 5 and 20 characters
  2. Breed must be one of the following: :arabean, :asian, :bengal, :persian
  3. Birthdate must be after 'today' (Date.today) and cat must not be older than 20 years.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment