Search⌘ K
AI Features

Example Design of a Feature

Explore how to structure a feature for editing widgets in Rails by dividing responsibilities among controllers, models, mailers, and service objects. Understand how to handle validations, notifications, and background jobs to keep business logic maintainable and separate from framework code, promoting sustainable app development.

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:

  1. A user views a form where they can edit a widget’s metadata.
  2. The user submits the form with a validation error.
  3. The form is rerendered, showing their errors.
  4. The user corrects the error and submits the edit again.
  5. The system then updates the database.
  6. 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.
  7. The user sees a result screen.
  8. Eventually, an email is sent to the right person.

This is not an uncommon ...