0
在Sinatra 1.1.0版中,我能够在before
块内使用configure
。在版本1.4.5中,这是不可能的。而是引发错误。使用configure之前的块
错误:
undefined method 'configure' for #<MySinatraServer:0x3f17a60>
file: web.rb location: block in <class:MySinatraServer> line:6
类定义:
require 'sinatra'
class MySinatraServer < Sinatra::Base
before do
configure :production do
halt 404, "insecure connection not allowed" if !request.secure?
end
end
get '/' do
"Hello Cruel World"
end
end
与thin start
运行,如下图所示config.ru:
map "/" do
run MySinatraServer
end
为什么配置内不再工作在块之前?
可能[this](http://stackoverflow.com/questions/10021869/how-to-define-a-method-to-be-called-from-the-configure-block-of-a-modular- sinatr)会有所帮助。 – zishe
这很好,但我不能访问before块之外的'request' var。我想知道是否可以通过Sinatra助手访问它。会给它一个镜头,谢谢 – Rots
@zishe不幸的是这有点混乱...在课堂上访问'请求'变种不是很漂亮。我设法以另一种方式解决了这个问题,这看起来相对简单。看看你的想法。 – Rots