Getting started:
-
Go here: github.com/vasaristudio/cf4-models
-
Fork the repository.
-
Clone your newly forked repository using the SSH clone URL at the bottom right of the repository view. This should look something like: git clone github.com/(your username)/cf4-models
-
cd cf4-models
-
bundle
-
rake db:migrate
-
rake db:seed
-
rails c
Files you will want to take special notice of:
-
all the model files in app/models
-
all the migration files in db/migrate
-
db/schema.rb - This is a representation of how your database is laid out.
-
db/seeds.rb - This is a place for you to enter sample data to get auto-imported
Use the rails generate command to generate a new model called Pet with the columns
-
person_id (integer)
-
name (string)
-
genus (string)
Associate the new Pet model with the Person model with a has_many association.
Edit your seeds file (see above) to make it auto-generate some fake pets owned by a person.
In the end, you should be able to do things such as:
-
person = Person.new
-
person.pets.count
-
person.pets.create(name: ‘Fluffy’, genus: ‘snake’)
-
person.pets.find_by(name: ‘Fluffy’)
When you have finished the above assignment, commit it up to Github and submit the URL for the changelog as your assignment.
Create a migration to add a gender column of type string to the person. Update the seeds file, migrate and run rake db:reset to reload the data from seeds.
After you are done, commit it up to Github and submit the URL for the changelog as your assignment.