Last active
August 30, 2018 15:59
-
-
Save manojmj92/69d2fe44d53e457574175f1f45fdecfc to your computer and use it in GitHub Desktop.
Interactor Example
This file contains hidden or 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
# Definition of the Interactor | |
class AuthenticateUser | |
include Interactor | |
def call | |
if user = User.authenticate(context.email, context.password) | |
context.user = user | |
context.token = user.secret_token | |
else | |
context.fail!(message: 'authenticate_user.failure') | |
end | |
end | |
end | |
# Invocation of the Interactor | |
class SessionsController < ApplicationController | |
def create | |
if user = AuthenticateUser.call(session_params) # session_params = { email: '[email protected]', password: 'blahblahblackheap'} | |
session[:user_token] = user.secret_token | |
redirect_to user | |
else | |
flash.now[:message] = 'Please try again.' | |
render :new | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment