Skip to content

Instantly share code, notes, and snippets.

@qoobaa
Created April 8, 2014 10:14
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 qoobaa/10106882 to your computer and use it in GitHub Desktop.
Save qoobaa/10106882 to your computer and use it in GitHub Desktop.
class V1::Client::SessionsController < V1::Client::ApplicationController
skip_before_action :authenticate, only: %i[create]
def create
@session = ::Client::Session.new(session_params)
@session.save
respond_with @session, location: nil
end
private
def session_params
params.require(:session).permit(:email, :password)
end
end
class Client::Session < ActiveModel::Session
def email=(email)
@email = email
@user = Client.find_by(email: email)
end
def save
valid? and user.generate_authentication_token!
end
def as_json(*)
{authentication_token: user.try(:authentication_token)}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment