我无法登出用户并清除用户的会话。我在rails服务器终端窗口中一直收到以下错误:
Started DELETE "/logout" for ::1 at 2014-12-01 17:17:47 -0500
ActionController::RoutingError (uninitialized constant SessoinsController):
以下是会话的控制器:
class SessionsController < ApplicationController
# SESSIONS ARE NOT AN ACTIVE RECORD MODEL
def new
end
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
log_in user
redirect_to user
else
# flash.now is used so when going to homepage the danger
# message is not there anymore
# designed for displaying flash on rendered pages
flash.now[:danger] = "Invalid email/password combination"
render 'new'
end
end
# logs out the current user, check session_helper for details
def destroy
log_out
redirect_to root_url, notice: "You have successfully logged out."
end
end
以下是会话助手: 模块SessionsHelper
# logs in the given user
def log_in(user)
session[:user_id] = user.id
end
# returns the current logged-in user (if any)
def current_user
@current_user ||= User.find_by(id: session[:user_id])
end
# returns true if the user is logged in, false otherwise
def logged_in?
!current_user.nil?
end
# logs out the current user
def log_out
session.delete(:user_id)
@current_user = nil
end
end
这是我的路线。
get 'users/new'
# These routes are from the static_pages controller
root 'static_pages#home'
get 'help' => 'static_pages#help'
get 'about' => 'static_pages#about'
get 'contact' => 'static_pages#contact'
get 'signup' => 'users#new'
get 'login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessoins#destroy'
resources :users
有人可以帮忙。提前谢谢。
答案 0 :(得分:1)
从路线中可以看出
logout DELETE /logout(.:format) sessoins#destroy
会话拼写错误
请确保此行正确无误:
delete 'logout' => 'sessions#destroy'