Created
March 18, 2019 01:45
-
-
Save lxbrito/c35efda5ee8d4034610212b5cc63547a to your computer and use it in GitHub Desktop.
ActiveBusinessController - Usage of ActiveBusiness on Controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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