未定义的方法已通过身份验证?表格 main::Object
Undefined method authenticated? form main::Object
我现在正在学习 Sinatra,并且正在创建一个小型博客。 authenticated?
方法有点问题。我已经设置了身份验证,现在我希望仅当用户通过身份验证时才加载我的应用程序的其余部分。所以,在我的 app.rb
中,我有以下内容:
helpers do
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
def authenticated?
redirect '/login' unless current_user
end
end
if authenticated?
# get '/' { ... }
# get '/new' { ... }
# post '/new' { ... }
# the rest of an app (creating, updating and deleting posts go here)
end
当我 运行 应用程序时,它 returns 我出现以下错误
undefined method authenticated? form main::Object
我做错了什么?
根据 docs,您将按如下方式使用 authenticated?
方法:
get '/' do
if authenticated?
# something
else
# something else
end
end
我现在正在学习 Sinatra,并且正在创建一个小型博客。 authenticated?
方法有点问题。我已经设置了身份验证,现在我希望仅当用户通过身份验证时才加载我的应用程序的其余部分。所以,在我的 app.rb
中,我有以下内容:
helpers do
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
def authenticated?
redirect '/login' unless current_user
end
end
if authenticated?
# get '/' { ... }
# get '/new' { ... }
# post '/new' { ... }
# the rest of an app (creating, updating and deleting posts go here)
end
当我 运行 应用程序时,它 returns 我出现以下错误
undefined method authenticated? form main::Object
我做错了什么?
根据 docs,您将按如下方式使用 authenticated?
方法:
get '/' do
if authenticated?
# something
else
# something else
end
end