Skip to content

Instantly share code, notes, and snippets.

@aishek
Last active August 29, 2015 14:05
Show Gist options
  • Save aishek/37d4a33619197548ab0a to your computer and use it in GitHub Desktop.
Save aishek/37d4a33619197548ab0a to your computer and use it in GitHub Desktop.
gem six auth concern usage example
# 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