▶️ Play from the beginning (~1 hour, 10 minutes)
In this demonstration, I will explain how to create interactive forms that access the model perform their function.
- ▶️ Prep: Review a wireframe diagram of the features we aim to build as well as the Rails architecture, giving special attention to the code we’ll need to add/modify.
- ▶️ Add a controller for the model class we created in the previous demo (see
rails generate controller ...
).
- ▶️ Add a route to the action that will render the form page.
- ▶️ Add a controller action for the form page, retrieving any record(s) needed to create the form.
- ▶️ Add a view that uses
form_tag
to create a form.
- Oops! In the video, forgot an
end
statement.
- Oops! Forgot that some record fields could be
nil
and should not be listed as radio button options. Fixed in the demo after next.
- ▶️ Test and debug: Restart the web server, and inspect the form in a browser.
- Oops! Missing
end
bug fixed here in the video.
- ▶️ Check in changes: Stage, commit, and push these changes to the Git repo (see
git add -A
, git commit ...
, and git push
).
▶️ Check-in Changes: changeset, snapshot
- ▶️ Prep: Review a wireframe diagram of the features we aim to build as well as the Rails architecture, giving special attention to the code we’ll need to add/modify.
- ▶️ Add a route to the action that will process the form submission.
- ▶️ Add a controller action for the form submission, accessing any record(s) needed to process the form submission and using
redirect_to
to redirect the browser back to the Home page.
- Oops! In the video, it should have been
include?
not includes?
.
- ▶️ Prep: Check out the Rails guide on the flash: https://guides.rubyonrails.org/action_controller_overview.html#the-flash.
- ▶️ Add flash
notice
/alert
messages to the redirects.
- Oops! The
alert
message contains a bug. Fixed in the demo after next.
▶️ 3. Adding Flash Messages
- ▶️ Prep: Check out the alert styles that Bootstrap provides: https://getbootstrap.com/docs/4.1/components/alerts/.
- ▶️ Update
application.html.erb
to display flash notice/alert messages.
- ▶️ Test and debug: Restart the web server, and test out the form in a browser.
- Oops!
include?
bug fixed here in the video.
- ▶️ Check in changes: Stage, commit, and push these changes to the Git repo (see
git add -A
, git commit ...
, and git push
).
▶️ Check-in Changes: changeset, snapshot
▶️ 4. Updating the Home Page and Clean Up Error Handling
- ▶️ Update the controller action for the Home page as appropriate.
- ▶️ Update the view for the Home page as appropriate. Test and debug as necessary.
- ▶️ Clean up error handling (see Ruby exception handling with
begin
/rescue
). Test and debug as necessary.
- ▶️ Check in changes: Stage, commit, and push these changes to the Git repo (see
git add -A
, git commit ...
, and git push
).
▶️ Check-in Changes: changeset, snapshot