Giter Site home page Giter Site logo

lab-rails-activerecord-models-migrations's Introduction

Models and migrations

Introduction

Note: This can be a pair programming activity or done independently.

You and the people at Tunr want to add some functionality to your talent management application. Specifically, they also want to be able to keep track of their managers and the songs their artists put out. Use Google and the ActiveRecord Official Docs if you need help and incorporate the requirements below to build on what you did in the previous lesson. Be sure to do these in order and keep an eye on your schema.rb file to see that your migrations are working properly! Also, think about the most appropriate datatype for each migration and use your discretion as you write them. The views and controllers are set up for you.

Exercise

Requirements

Part 1

You can use rails g scaffold to generate the model, view and controller files in one go in this part.

  • Create a manager class that inherits from ActiveRecord

    • For this class, create a table in your database and the corresponding forms that collect and display information about the manager's name, email, and office number.
  • Create a song class that inherits from ActiveRecord

    • For this class, create a table in your database and the corresponding forms that collect and display information about the song title, duration, year of release, and album title.
  • Remember to do rake db:migrate

Part 2

Since the model files have been generated already so you can no longer use rails g scaffold in this part of the lab. Instead, you can try to generate the migration scripts using rails g migration manually and then make the changes to the model, view and controller files by hand.

  • Add a phone number column to the manager table as an integer
  • Change the phone number column to a string
  • Add a downloads column to the song table
  • Rename the phone number column to "cell phone number" in the managers table
  • Remove the downloads column from the song table
  • Add a column to the song table called artist last name

Testing

  • In order to make sure all is working well, Add one record for artist, manager, and song that has this information:

  • Artist:

  • Manager:

    • Name: Ricky Bobby
    • Email: [email protected]
    • Office Number: 516-877-0304
    • Cell Phone Number: 718-989-1231
  • Song:

    • Title: The Best Song Ever
    • Duration: 3:31
    • Date of Release: 7/13/2015
    • Album Title: Best Album Ever
    • Artist Last Name: Rox

Bonus

  1. Try to update the *.erb.html view files so that the changes to the DB columns in Part 2 can be reflected in the application? erb is just similar to ejs so you should have no trouble using it!!
  2. If you still have time and you don't like the look-and-feel of the scaffold, feel free to update the HTML/CSS!!

Starter code

Fork and Clone this repo and start working

Deliverable

A whole bunch of migrations, and your schema.rb file should look like this:

Additional Resources

lab-rails-activerecord-models-migrations's People

Contributors

dshcheung avatar sytong avatar

Watchers

 avatar  avatar

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.