class SessionsController < ApplicationController
def new
end
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
session[:user_id] = user.id
flash[:success] ="You have successfully logged in"
redirect_to users_path(user)
else
flash.now[:danger] = "Invalid email or password"
render 'new'
end
end
def destroy
session[:user_id] = nil
flash[:success] = "Successfully logged out"
redirect_to root_path
end
end
This is my error 未定義的方法`downcase」的零:NilClass Ruby on Rails的
這裏是routes.rb中
get 'login', to: 'sessions#new'
post 'login', to: 'sessions#create'
delete 'logout', to: 'sessions#destroy'
你可以嘗試改變':session'到:sessions'並讓我知道它是否工作? –
感謝您的答覆..但它說:「未定義的方法'[]爲零:NilClass」 –