
Give your services "verby" names, e.g.Both approaches are fine, pick one and stick to it. Not using a namespace saves you from writing Services:: everytime you want to reference a service in your app. you can have a Services::Maintenance service, yet also a Maintenance module in lib). Namespacing your service allows you to use a name for them that some other class or module in your app has (e.g. Decide if you want to use a Services namespace or not.Let your query objects inherit from Services::Query.Let your services inherit from Services::Base.Conventionsįollow these conventions when using Services in your Rails app, and you'll be fine:
#Rails services free

Requirements Ruby >= 2.7 Rails >= 6.0 Redis >= 3.0 Usageįor disambiguation: in this README, when you read "Services" with a uppercase "S", this gem is meant, whereas with "services", well, the plural of service is meant.

The biggest benefit you get when using a service layer, in my opinion, is that it gets so much easier to reason about your application, find a bug, or implement new features, when all your business logic is in services, not scattered in models, controllers, helpers etc. There are of course advantages and disadvantages, but after using Services since 2013 in several Rails apps, I must say that in my opinion the advantages far outweigh the disadvantages. MotivationĪ lot has been written about service layers (service objects, SOA, etc.) for Rails. Services is a collection of modules and base classes that let you simply add a service layer to your Rails app.
