Skip to content

Instantly share code, notes, and snippets.

@elskwid
Created October 24, 2014 01:04
Show Gist options
  • Save elskwid/a12df9e603c6e2fb6d21 to your computer and use it in GitHub Desktop.
Save elskwid/a12df9e603c6e2fb6d21 to your computer and use it in GitHub Desktop.
Final Countdown

Rails Fundamentals The Final Countdown

Move our original project:

  • change to the home directory:

    • cd ~
  • move course_catalog to cource_catalog_original:

    • mv course_catalog course_catalog_original
  • check your work with:

    • ls

Update gems to the latest version:

Note: we're still in our home directory

  • update installed gems
    • gem update

Create our new project:

  • rails new course_catalog

Scaffold our domain:

Course
  - title, String
  - description, String (longer text)
  - prereqs, String

Instructor
  - first_name, String
  - last_name, String
  
Section
  - course, Course
  - instructors, Instructor
  - subtitle, String
  - location, String
  - area, String
  - units, String

Remember: Course --* Section Section --* Instructor

  • scaffold the course:

    • bin/rails generate scaffold course title description:text prereqs
  • scaffold the instructor:

    • bin/rails generate scaffold instructor first_name last_name
  • scaffold the section

    • bin/rails generate scaffold section course:references subtitle location area units
  • generate the join table for instructors and sections (it will be called instructors_sections)

    • bin/rails generate migration create_instructors_sections instructor:references section:references
  • migrate our database tables

    • bin/rake db:migrate

Create our associations:

Course has many sections

  • open app/models/course
  • add has_many :sections

Section belongs to Course

  • open app/models/section
  • add belongs_to :course (scaffolding may have done this for you)

Section has and belongs to many instructors Instructor has and belongs to many sections

  • open app/models/section

  • add has_and_belongs_to_many :instructors

  • open app/models/instructor

  • add has_and_belongs_to_many :sections

Nest Section resources under Courses

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment