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?
It’s solves the problem because Sinatra doesn’t have
Defaultclass anymore. And if you want to access some settings defined with:setyou should usesettings.for this.