Coder Social home page Coder Social logo

cf4-models's Introduction

Example for Databases, Models, and Migrations class

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

Assignment:

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.

Extra Credit:

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.