Posted over 3 years ago. Visible to the public.

Form models

Reading

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

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

Exercises

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.
    • Implement the 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.
  • 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:

Avatar
Henning Koch
Last edit:
over 1 year ago
by Michael Leimstädtner
Keywords:
form, objects
Posted by Henning Koch to makandra Curriculum
This website uses cookies to improve usability and analyze traffic.
Accept or learn more