未初始化的常量LoginController

问题描述 投票:0回答:1

这是我的控制器

class LoginsController < ApplicationController

  def new

  end

  def create
    student = Student.find_by(email: params[:logins][:email].downcase)
    if student && student.authenticate(params[:logins][:password])
      session[:student_id] = student.id
      flash[:notice] = "You have successfully logged in"
      redirect_to student
    else
      flash.now[:notice] = "Something was wrong with your login information"
      render 'new'
    end
  end

  def destroy
    session[:student_id] = nil
    flash[:notice] =  "You have successfully logged out"
    redirect_to root_path
  end

end

这是我的路线

 get 'login', to: 'logins#new'
  post 'login', to: 'logins#create'
  delete 'logout', to: 'login#destroy'

当我点击注销按钮时,它给出了路由错误未初始化的常量LoginController

这是link项目的github链接

ruby-on-rails ruby ruby-on-rails-5
1个回答
1
投票

您的路线中存在拼写错误:

更改删除'logout',以:'login#destroy'删除'logout',至:'logins#destroy'

© www.soinside.com 2019 - 2024. All rights reserved.