打开它时,我在浏览器中显示此消息。我使用的是Rails 5.1.1,ruby 2.4.1,puma 3.9.1。
"未定义的方法`签名'为零:NilClass"指的是cookies.signed
我在Rails 5.0.3中有相同的项目并且它正在工作。我对这条线路进行了评论,但它在每一行都崩溃了#34; cookies"。我试图启动一个新的Rails项目,但问题仍然存在。这是Rails 5.1.1的问题吗?
我的sessions_helper.rb文件包含以下代码:
# frozen_string_literal: true
# Helper for Sessions
module SessionsHelper
# Logs in the given user.
def log_in(user)
session[:user_id] = user.id
end
# Remembers a user in a persistent session.
def remember(user)
user.remember
cookies.permanent.signed[:user_id] = user.id
cookies.permanent[:remember_token] = user.remember_token
end
# Returns the user corresponding to the remember token cookie.
def current_user
if (user_id = session[:user_id])
@current_user ||= User.find_by(id: user_id)
elsif (user_id = cookies.signed[:user_id]) # Error in this line
user = User.find_by(id: user_id)
if user && user.authenticated?(cookies[:remember_token])
log_in user
@current_user = user
end
end
end
# Returns true if the user is logged in, false otherwise.
def logged_in?
!current_user.nil?
end
# Forgets a persistent session.
def forget(user)
user.forget
cookies.delete(:user_id)
cookies.delete(:remember_token)
end
# Logs out the current user.
def log_out
forget(current_user)
session.delete(:user_id)
@current_user = nil
end
end