Skip to content

Instantly share code, notes, and snippets.

@bibhuticoder
Created May 1, 2019 03:39
Show Gist options
  • Save bibhuticoder/c2840fd1f728e45c1513938851accd8f to your computer and use it in GitHub Desktop.
Save bibhuticoder/c2840fd1f728e45c1513938851accd8f to your computer and use it in GitHub Desktop.
class ExampleController < ApplicationController
before_action :res1, only: [:action_1, :action_2]
before_action :res2, only: [:action_3, :action_4]
def action_1
# rest of the logic....
render json: {data: '...'}, status: 200
end
def action_2
# rest of the logic....
render json: {data: '...'}, status: 200
end
def action_3
# rest of the logic....
render json: {data: '...'}, status: 200
end
def action_4
# rest of the logic....
render json: {data: '...'}, status: 200
end
private
def res_1
# perform some operations
render json: {message: 'Failed'}, status: 400 unless operation1_successful?
end
def res_2
# perform some operations
render json: {message: 'Failed'}, status: 400 unless operation1_successful?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment