Skip to content

Latest commit

 

History

History

services

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Ruby on Rails Services

Introduction

Rails services isn't in default app/ structure. We create this folder to help to mantain controllers and models clean. Services is a layer between them. Usually it has business logic and integration between others apps.

Class methods and object methods

When calling a service is good pattern show what we're calling. Things like PaymentService.new(card, value).process! is better than PaymentService.process(card, value) because if we want try if card credit is valid before, we memoize the object into 'def payment' and use payment.valid? ? payment.process : fail InvalidCardError like sample.rb

Never forget

  • Sandy Metz Rules
  • Hound CI is good to validate code style and other things.
  • Use ActiveRecord::Base.transaction to keep all process methods in transaction. Good pattern to rollback when a method fail and keep previous database status.
  • SOLID principles