Skip to content

Instantly share code, notes, and snippets.

@timurvafin
Created May 11, 2015 12:57
Show Gist options
  • Save timurvafin/816dd58467cbc955feec to your computer and use it in GitHub Desktop.
Save timurvafin/816dd58467cbc955feec to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
include Authentication
include Authorization
protect_from_forgery
responders :flash
decent_configuration do
strategy DecentExposure::StrongParametersStrategy
end
end
module Authentication
extend ActiveSupport::Concern
included do
helper do
def current_user
UserPresenter.new(warden.authenticate(scope: :user))
end
end
end
private
def devise_parameter_sanitizer
if resource_class == User
User::ParameterSanitizer.new(User, :user, params)
else
super
end
end
end
module Authorization
extend ActiveSupport::Concern
included do
include Pundit
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
end
private
def user_not_authorized
redirect_to(root_path)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment