Pro Yearly is on sale from $80 to $50! »

Off the Rails: Patterns for fixing fat models, out-of-controllers, and other Rails problems

Off the Rails: Patterns for fixing fat models, out-of-controllers, and other Rails problems

4109276dec776c9999af7ba023d902b6?s=128

Alexander Clark

April 23, 2019
Tweet

Transcript

  1. Off the Rails Patterns for fixing fat models, out-of-controllers, and

    other Rails problems
  2. What I’m about to tell you is wrong.

  3. YMMV

  4. MVC

  5. View Controller Model

  6. 3 Tier Architecture

  7. Business Logic Presentation Data

  8. Business Logic Presentation Data

  9. Business Logic Presentation Data View Controller Model

  10. Business Logic Presentation Data View Controller Model

  11. View Controller Model Business Logic Presentation Data

  12. None
  13. None
  14. None
  15. View Controller Model

  16. Model Service View Controller

  17. Business Logic Presentation Data

  18. Business Logic Presentation Data

  19. Business Logic Presentation Data Service

  20. None
  21. None
  22. Controller Rule of Thumb A Controller May Contain: • Public

    REST methods • Private before_action setters • Private strong params method
  23. Models

  24. Business Logic Presentation Data View Controller Model

  25. Business Logic Presentation Data View Controller Model

  26. Business Logic Presentation Data View Controller Model Repository

  27. None
  28. Business Logic Presentation Data View Controller Validator Model

  29. None
  30. None
  31. None
  32. None
  33. –Sandi Metz “duplication is far cheaper than the wrong abstraction”

  34. YAGNI

  35. Bonus Tip

  36. None
  37. None
  38. Thanks for Listening Alexander Clark atheclark alexander-clark.com alexander-clark

  39. Further reading • https://codeclimate.com/blog/7-ways-to-decompose-fat- activerecord-models/ • Patterns of Enterprise Application

    Architecture (Fowler) • Domain Driven Design (Evans) • All the Little Things (Metz) https://www.youtube.com/ watch?v=8bZh5LMaSmE • Ruby Object Mapper https://rom-rb.org/
  40. Questions?