Skip to content

Instantly share code, notes, and snippets.

@ouranos
Created May 25, 2015 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ouranos/55fa0bb65b9b0de9a4e8 to your computer and use it in GitHub Desktop.
Save ouranos/55fa0bb65b9b0de9a4e8 to your computer and use it in GitHub Desktop.
# app/controllers/application_controller.rb
class ApplicationController < ActionController::API
include WardenHelper
end
# app/controllers/concerns/warden_helper.rb
module WardenHelper
extend ActiveSupport::Concern
included do
helper_method :warden, :signed_in?, :current_user
prepend_before_filter :authenticate!
end
def signed_in?
!current_user.nil?
end
def current_user
warden.user
end
def warden
request.env['warden']
end
def authenticate!
warden.authenticate!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment