Last active
August 29, 2015 14:05
-
-
Save aishek/37d4a33619197548ab0a to your computer and use it in GitHub Desktop.
gem six auth concern usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/controllers/web/application_controller.rb | |
class Web::ApplicationController < ApplicationController | |
include Concerns::Auth | |
rescue_from AccessDenied, :with => :access_denied_handler | |
private | |
def can?(action, subject = current_user) | |
abilities << subject | |
abilities.allowed?(current_user, action, subject) | |
end | |
def current_user_session | |
@current_user_session ||= ::User::Session.find | |
end | |
def current_user | |
@current_user ||= (current_user_session && current_user_session.record) || Guest.new | |
end | |
def access_denied_handler | |
flash[:error] = t('helpers.auth.unauthorized') | |
redirect_back_or_default auth_login_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment