Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 1.81 KB

forms.md

File metadata and controls

33 lines (23 loc) · 1.81 KB

Forms

Why

Forms are crucial to nearly all apps. They tend to comprise much of an app's view layer complexity. For that reason, consistent design & user interaction is very important.

Tools

SimpleForm

Useful Patterns (embrace these)

  • ActiveModel Form Objects
  • Lean on existing Policies for collection scoping
  • custom inputs

Code Smells (avoid these)

  1. Passing lots of configuration options into input helpers. In most cases, f.input :attr_name should be sufficient.
    • If you find yourself passing the same options over and over again, those options probably belong in config/initializers/simpleform.rb
    • consider implementing a custom input f.input :total_cost, as: :currency
  2. Explicitly setting the form action (url option)
  3. Custom Stimulus controllers used on only 1 form
    • This boils down to consistency. Forms are often where we want to leverage JavaScript to enhance the user experience. However, custom behavior should feel consistent between forms & Stimulus is flexible enough that you should be able to reuse the same controller between forms. So long as your forms adhere to the other patterns mentioned in this document.
  4. turbo: false
    • Turbo is a core component of modern Rails apps. Turning it off is an indication that something is broken.

Resources