For this practice lab, you'll be working with Student-Instructor domain.
In this repo, there is a Rails application with some features built out. Your job is to extend this code to add the functionality described in the deliverables below.
- MVC
- REST
- Request-Response Cycle
- Forms and Form Helpers
- ActiveRecord
- Validations
Before you begin coding your solution, fork and clone this repo and then cd
into it. Then run bundle install
, rails db:migrate
, and rails db:seed
to install dependencies and set up the database, and run rails s
to start the server.
The application keeps track of the students.
There are two models in the domain: Student and Instructor.
Instructor has many students and student belongs to an instructor.
The starter code includes migrations, models, and seed data for Students and Instructors. There are also routes, controller actions, and views to support listing the students and instructors.
After running the setup instructions above, visiting '/students'
will display all of the students, and visiting '/instructors'
will display all of the instructors.
Schema
Instructors
Column | Type |
---|---|
name | String |
created_at | DateTime |
updated_at | DateTime |
Students
Column | Type |
---|---|
name | String |
major | String |
age | Integer |
instructor_id | Integer |
created_at | DateTime |
updated_at | DateTime |
- None
- Students index
- Instrucor index
Update the code of the application to meet the following deliverables. Follow RESTful naming conventions and the MVC pattern to divide responsibility.
Read through these deliverables carefully to understand the requirements for this code challenge practice. Tackle them one by one, as they build on each other sequentially.
A user can fill out a form to create a new Student. They can:
- Enter a name
- Enter a major
- Choose an existing instructor from a select dropdown
- Enter a numeric age
- Submit the form
After submitting the form, the user should be redirected to the selected instructor's show page.
On the instructor show page, a user should see:
- Instructor's name
- A list of the students who belongs to this instructor
- Each student's name should link to the Student Show page
On the student's show page,
- Student's name
- Instrcutor's name for that student
- Instrcutor's name should link to the Instrcutor Show page
- Add a validation to ensure that the student's age is greater than 18.
- Add handling for this error to the Student create action.
- The validation error should be shown on the Student creation form when a user attempts to save a student with an invalid age.
A user can fill out a form to update an existing Student. They can:
- Change a name
- Change a major
- Change an existing instructor from a select dropdown
- Change an age
- Submit the form
After submitting the form, the user should be redirected to the student's show page.
On the Instrcutor's show page, show the average age of the students for the instrcutor.
On the Instructor show page, display the Students name in alphabetical order.
You can find the rubric for the Code Challenge here.