Created
July 3, 2014 03:50
-
-
Save cthornton/7b47f978b9b1e58c1526 to your computer and use it in GitHub Desktop.
Sample API Controller
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
class ApiController < ActionController::Base | |
attr_reader :current_user | |
before_action :find_current_user | |
protected | |
def find_current_user | |
@current_user = User.find_by(api_key: request.authorization) | |
unless @current_user | |
render json: { error: 'Cannot find user by API key' }, status: :unauthorized | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment