Skip to content

Instantly share code, notes, and snippets.

@cthornton
Created July 3, 2014 03:50
Show Gist options
  • Save cthornton/7b47f978b9b1e58c1526 to your computer and use it in GitHub Desktop.
Save cthornton/7b47f978b9b1e58c1526 to your computer and use it in GitHub Desktop.
Sample API Controller
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