Example Design of a Feature
Learn about the design feature of editing the widget in our Rails application.
We'll cover the following
Requirements for editing a widget
Suppose we are building a feature to edit widgets. Here is a rough outline of the requirements around how it should work:
- A user views a form where they can edit a widget’s metadata.
- The user submits the form with a validation error.
- The form is rerendered, showing their errors.
- The user corrects the error and submits the edit again.
- The system then updates the database.
- When the widget is updated, two things have to happen:
- Depending on the widget’s manufacturer, we need to notify an admin to approve the changes.
- If the widget is of a particular type, we must update an inventory table used for reporting.
- The user sees a result screen.
- Eventually, an email is sent to the right person.
This is not an uncommon amount of complexity. We’ll have to write a bit of code to make this work, and it’s necessarily going to be in several places. A controller will need to receive the HTTP request, a view will need to render the form, a model must help with validation, a mailer will need to be created for the emails we’ll send, and somewhere in there, we have a bit of our own logic.
The figure below shows the classes and files that would be involved in this feature. The WidgetEditingService
is probably sticking out to us.
Get hands-on with 1200+ tech skills courses.