Rails service objects vs lib classes

This is how I tend to think about code that goes in lib/:

  • It is not coupled to my app’s domain models.
  • It can be reused on other projects.
  • It can potentially become its own gem. Thus, putting it in lib/ is the first step in that direction.

Services:

  • They tend to know a decent amount about the inner workings of domain models.
  • Perform work that is specific to business domain in my app.
  • Tend to be coupled to specific models.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)