Sinatra 授权扩展:NameError
谁能告诉我为什么在调用 /admin
路由时出现 NameError - uninitializedconstant Sinatra::Default
?
require "sinatra"
require "sinatra/authorization"
set :authorization_realm, "Protected zone"
helpers do
def authorize(login, password)
login == "admin" && password == "secret"
end
end
get "/" do
"Welcome to the public zone"
end
get "/admin" do
login_required
"Welcome to the protected zone"
end
我使用的是 Ruby 1.9.2、Sinatra 1.2.6 和 Sinatra 授权扩展。
更新:好的,我在以下文件的第 25 行找到了问题的根源:
sinatra-authorization-1.0.0/lib/sinatra/authorization.rb
原始项目的这个分支通过替换解决了问题Sinatra::Default.authorization_realm
和 settings.authorization_realm
在第 25 行。这解决了问题,但我不明白为什么。谁能向我解释一下吗?
Can anyone tell me why I get a NameError - uninitialized constant Sinatra::Default
when calling the /admin
route?
require "sinatra"
require "sinatra/authorization"
set :authorization_realm, "Protected zone"
helpers do
def authorize(login, password)
login == "admin" && password == "secret"
end
end
get "/" do
"Welcome to the public zone"
end
get "/admin" do
login_required
"Welcome to the protected zone"
end
I'm using Ruby 1.9.2, Sinatra 1.2.6 and the Sinatra Authorization Extension.
UPDATE: OK, I've found the source of the problem at line 25 of the following file:
sinatra-authorization-1.0.0/lib/sinatra/authorization.rb
This fork of the original project solved the problem by replacing Sinatra::Default.authorization_realm
with settings.authorization_realm
at line 25. This solves the problem, but I don't understand why. Can anyone explain that to me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它解决了问题,因为 Sinatra 不再有
Default
类。如果您想访问使用:set
定义的某些设置,您应该使用settings.
。It's solves the problem because Sinatra doesn't have
Default
class anymore. And if you want to access some settings defined with:set
you should usesettings.
for this.