- Use
form_for
to build anew
form - Use
form_for
to build anedit
form - Mass assign form data to
ActiveRecord
instances onnew
andedit
- Build RESTFul actions for
new
,create
,edit
, andupdate
, with the correct routes and route helper urls.
For this lab you will be extending the functionality of the Flatiron school's student management application by building in the functionality to create and edit school classes. You will build all of the functionality from scratch, including building out the models, views, and controllers for the SchoolClass
and Student
resources.
Below is what will be needed for each component of the MVC structure:
-
Models - Create a
SchoolClass
model, along with its associated database table. TheSchoolClass
table should have the columns:title:string
androom_number:integer
. TheStudent
model and database table have already been created for you. -
Controllers - Create controller files for
school_classes
andstudents
. Build out thenew
,create
,show
,edit
, andupdate
actions in each of the controllers. -
Views - Create a show page for each resource, along with
new
andedit
forms.
You will also need to create routes for each path mentioned above.
The tests for this application are located in the spec/controllers/
, spec/features/
, and spec/models/
directories.
Utilize the form_for
methods for all four of the forms and integrate each form_for
call with the respective controller actions. Also make sure to utilize the <%= f.submit %>
submit button syntax to have the button text automatically generated.
Since you're using form_for
, make sure you are using strong parameters for the controller create
and update
actions, if you don't remember how to do it, here is how we implemented strong params in the README: @post.update(params.require(:post).permit(:title, :description))
. (Hint: you can pass the strong parameter call to the create
method just like we did on update
.)
If you run into issues drawing the routes, navigate to the form in your browser and use inspect element to see what path form_for
is automatically trying to pass the form data to.