app/controllers/login_controller.rb
def login
    @request_user = User.new(user_params)

    user = User.find_by(email: @request_user.email)

    if user&.authenticate(@request_user.password)
      session[:user_id] = user.id
      redirect_to root_path
    else
      flash[:error] = 'Email or password is invalid'
      redirect_to action: :login_form
    end
  end
# Authenticates a user and saves user id in session
Authenticates a user and saves user id in session
Authenticates a user and saves user id in session
def login
    @request_user = User.new(user_params)
    user = User.find_by(email: @request_user.email)
    if user&.authenticate(@request_user.password)
      session[:user_id] = user.id
      redirect_to root_path
    else
      flash[:error] = 'Email or password is invalid'
      redirect_to action: :login_form
    end
  end
def login @request_user = User . new ( user_params ) user = User . find_by ( email : @request_user . email ) if user &. authenticate ( @request_user . password ) session [ :user_id ] = user . id redirect_to root_path else flash [ :error ] = 'Email or password is invalid' redirect_to action : :login_form end end
Authenticates a user and saves user id in session
Authenticates a user and saves user id in session