Skip to content

Instantly share code, notes, and snippets.

@bibhuticoder
Created May 1, 2019 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bibhuticoder/5a810f15179590c81fe0740b165e4311 to your computer and use it in GitHub Desktop.
Save bibhuticoder/5a810f15179590c81fe0740b165e4311 to your computer and use it in GitHub Desktop.
class ExampleController < ApplicationController
def action_1
if res1.eql?(false)
render json: {message: 'Failed'}, status: 400 unless res_1
return
end
# rest of the logic....
render json: {data: '...'}, status: 200
end
def action_2
if res1.eql?(false)
render json: {message: 'Failed'}, status: 400 unless res_1
return
end
# rest of the logic....
render json: {data: '...'}, status: 200
end
def action_3
if res2.eql?(false)
render json: {message: 'Failed'}, status: 400 unless res_2
return
end
# rest of the logic....
render json: {data: '...'}, status: 200
end
def action_4
if res2.eql?(false)
render json: {message: 'Failed'}, status: 400 unless res_2
return
end
# rest of the logic....
render json: {data: '...'}, status: 200
end
private
def res_1
# perform some operations
(operation1_successful?) ? true : false
end
def res_2
# perform some operations
(operation2_successful?) ? true : false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment