Sha256: 1fe111f6a63f05961b12456fd4943b43b15d06f026d5fde402602a704e182bd7
Contents?: true
Size: 747 Bytes
Versions: 8
Compression:
Stored size: 747 Bytes
Contents
module V1 module Concerns module ControllerBase extend ActiveSupport::Concern # Controller concen that wraps an API with a transaction, and automatically rolls it back # for non-2xx (or 3xx) responses included do around :action do |controller, callee| begin ActiveRecord::Base.transaction do callee.call res = controller.response # Force a rollback for non 2xx or 3xx responses raise ActiveRecord::Rollback unless res.status >= 200 && res.status < 400 end rescue ActiveRecord::Rollback # No need to do anything, let the responses flow normally end end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems