Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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