1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lpr-partynest/app/controllers/application_controller.rb
2018-11-30 05:17:26 +05:00

35 lines
810 B
Ruby

# frozen_string_literal: true
class ApplicationController < ActionController::Base
include Pundit
before_action :set_raven_context
protect_from_forgery with: :exception
skip_forgery_protection if: :json_request?
after_action :verify_authorized, except: :index
after_action :verify_policy_scoped, only: :index
rescue_from ActiveRecord::RecordNotFound, with: :not_found
rescue_from NotAuthorizedError, with: :unauthorized
private
def set_raven_context
Raven.user_context id: current_user.id if user_signed_in?
Raven.extra_context params: params.to_unsafe_h, url: request.url
end
def json_request?
request.format.json?
end
def not_found
render status: :not_found, json: {}
end
def unauthorized
render status: :unauthorized, json: {}
end
end