-
change to the home directory:
cd ~
-
move course_catalog to cource_catalog_original:
mv course_catalog course_catalog_original
-
check your work with:
ls
Note: we're still in our home directory
- update installed gems
- gem update
- rails new course_catalog
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
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