Created
April 4, 2019 21:13
-
-
Save localhostdotdev/a11ead42295efd93d0f9ec0a405aa9f1 to your computer and use it in GitHub Desktop.
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
# frozen_string_literal: true | |
class UserService | |
include SessionsHelper | |
def sigin_user | |
user = User.find_by_email(@email) | |
if user.present? | |
login(user) | |
response = { success: 'User Logged In successfully.' } | |
else | |
response = { error: user.errors.full_messages.join('<br/>') }.with_indifferent_access | |
end | |
end | |
end | |
class SessionsController < ApplicationController | |
def create | |
user = login_user | |
if user[:error].present? | |
flash[:error] = user[:error] | |
else | |
flash[:success] = user[:success] | |
end | |
end | |
private | |
def login_user | |
UserService.new(login_params).sigin_user | |
end | |
end | |
# Whereas here is my SessionsHelper | |
# | |
module SessionsHelper | |
def login(user) | |
session[:user_id] = user.id | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.reddit.com/r/rails/comments/b9ifis/help_unable_to_include_actioncontrollerbase_in/