Skip to content

Instantly share code, notes, and snippets.

@lxbrito
Created March 18, 2019 01:45
Show Gist options
  • Save lxbrito/c35efda5ee8d4034610212b5cc63547a to your computer and use it in GitHub Desktop.
Save lxbrito/c35efda5ee8d4034610212b5cc63547a to your computer and use it in GitHub Desktop.
ActiveBusinessController - Usage of ActiveBusiness on Controller
# frozen_string_literal: true
# :nodoc:
class ActiveBussinessController < AplicationController
def some_action
# Dealing with params is a controller's responsibility
arg = collect_and_validate_your_params
YourActiveBusinessImplementation.call(arg) do |resp|
resp.success { |payload| render json: payload.to_json, status: 2xx }
resp.error { |message| render json: { message: message }.to_json, status: 4xx }
# You can define other outputs like an idempotent success
resp.nothing_changed { head 204 }
end
rescue SomeException => ex
# treat exception
render json: "Something happened", status: 500
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment