Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@lackac /
Last active Aug 29, 2015

2 Ways to Decompose Fat ActiveRecord Models – budapest.rb 03/2014


  • Fat Model, Skinny Controller
  • Object-Oriented Design Patterns
  • Single Responsibility Principle

2 Ways to Decompose Fat ActiveRecord Models

Query Object

Purpose: encapsulate complex queries


  • no unwieldy SQL in model
  • keeps benefits of AR scopes



Service Objects

Purpose: encapsulate complex actions, concerns, or responsibilities that reach across multiple models


  • SRP makes maintenance easier
  • developers know where to go to tweak behavior
  • easier to test
  • tends to make codebase DRYer



Further Reading

  • Practical Object-Oriented Design in Ruby, by Sandi Metz
  • Objects on Rails, by Avdi Grim
  • Refactoring: Ruby Edition, by Jay Fields, Shane Harvie, Martin Fowler, Kent Beck (mentioned in the discussion)


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.