Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Zen and the Art of the Controller

Zen and the Art of the Controller

So you’re fresh out of boot camp or just off a month long binge on RoR tutorials/examples and you’re feeling pretty good about MVC and how controllers fit into the whole framework. But projects in the wild are often far more complicated than you’ve been exposed to. In this talk, we’re going to discuss several techniques used by seasoned engineers to build and refactor controllers for features you’ll actually be working on.

Michael Kelly

May 04, 2016
Tweet

Other Decks in Programming

Transcript

  1. Full-Stack Rails Controller Actions: 1. Index 2. Show 3. New

    4. Create 5. Edit 6. Update 7. Destroy
  2. So how does this happen? Usual Suspects: 1. Changing requirements

    2. Feature growth 3. Changes to the developer/team 4. Refactors from other areas of the app What really happened: A misunderstanding what resource an action is ACTUALLY dealing with
  3. Example: Social Ad SaaS Tool Requirements: • A tool to

    browse, read, add, edit, and delete ads on a social platform • Ads can be paused, activated, or archived • Users must be able to view their ads’ performance
  4. AdsController Basic BREAD (or CRUD) on Ad objects 1. Index

    2. Show 3. New 4. Create 5. Edit 6. Update 7. Destroy Action Count: 7
  5. AdsController Job Actions to Change Ad Status 1. Pause 2.

    Activate 3. Archive Action Count: 10
  6. Said by every exec, everywhere: Can we make the UI,

    I don’t know, cooler...you know...with javascripts or something?
  7. BREAK IT UP Break a controller up into smaller, more

    accurate pieces by looking at what kind of resource your actions are ACTUALLY working with
  8. Other Types of Controllers To Think About 1. Static or

    View Layer Controllers 2. Composite Controllers 3. Aggregate Controllers
  9. Static/View Controllers Controllers that only function to provide a static

    view or to provide front-end access to a “view” of your domain model
  10. AdsController Basic BREAD on Ad objects 1. Index 2. Show

    3. New 4. Create 5. Edit 6. Update 7. Destroy
  11. Why do we do this? 1. Easier Debugging and source

    navigation 2. Learning and Onboarding 3. Localized/Domain changes 4. Easier to coordinate large teams working on the same code
  12. Questions/Comments? • Look at what your actions are ACTUALLY working

    on • Break up your controllers to keep them lean n’ mean The Takeaway Or after the talk @thebadmonkeydev