Posted about 5 years ago. Visible to the public.

Form models [2d]


Read (or re-read) the following chapters from our book Growing Rails Applications in Practice (it’s in our library):

  • New rules for Rails
    • Beautiful controllers
    • Relearning ActiveRecord
    • User interactions without a database
  • Creating a system for growth
    • Dealing with fat models
    • A home for interaction-specific code
    • Extracting service objects
    • Organizing large codebases with namespaces

Watch Tobias Pfeiffer's talk: Do You Need That Validation? Let Me Call You Back About It

Talk with your mentor about the motivations behind the use of form models.


Go through the repos of Cards and/or MovieDB and apply what you learned:

  • Create a form model backed by a database
    • Have two different forms to create a user: One for public sign up, one in a private admin area
    • The sign up form sends a welcome e-mail and checks for password policy, the admin form doesn't.
      • If you are struggling with this, just have a method send_welcome_email that does nothing. If time allows, try changing this to send a simple e-mail once you are done with everything else in this card.
    • Implement the public sign up form once as an ActiveType::Object and once as an ActiveType::Record[User]. What are the pros and cons of each approach?
  • Create a form model not backed by a database
    • Implement the login form using ActiveType::Object
    • Implement a screen to merge two movies.
      • Flat attributes are copied from the first movies
      • Lists of actors are merged, but actors found in both lists are only kept once.
      • Showtimes are merged as well (hint: this is easier than merging actors), discarding duplicates.
      • The first movie is destroyed after successfully merging into the second movie.
  • Find and talk about examples where a method should better live in a callback and vice versa
  • Find a composition of classes and move the child classes into the namespace of the container class.
  • Move a group of related classes into a namespace.

Owner of this card:

Henning Koch
Last edit:
5 months ago
by Henning Koch
form, objects
Posted by Henning Koch to makandra Curriculum
This website uses short-lived cookies to improve usability.
Accept or learn more