0
嗨,所有的, 我認爲這是一個關於在sinatra中定義的常量的bug,讓我們來看看我的代碼。已經初始化常量,並且需要兩次
route.rb
require 'sinatra'
get '/' do
C = "this is a test for constant"
"Hello World!"
end
的Gemfile
source 'http://rubygems.org'
gem 'rack'
gem 'sinatra'
config.ru
require './route'
run Sinatra::Application
啓動Web服務器,我們將看到下面
$ rackup
[2011-10-08 19:54:36] INFO WEBrick 1.3.1
[2011-10-08 19:54:36] INFO ruby 1.9.2 (2011-07-09) [i686-linux]
[2011-10-08 19:54:36] INFO WEBrick::HTTPServer#start: pid=3268 port=9292
127.0.0.1 - - [08/Oct/2011 19:54:42] "GET/HTTP/1.1" 200 25 0.0059
127.0.0.1 - - [08/Oct/2011 19:54:42] "GET/HTTP/1.1" 200 25 0.0142
/home/zcdny/repo/test/route.rb:4: warning: already initialized constant C
127.0.0.1 - - [08/Oct/2011 19:54:43] "GET/HTTP/1.1" 200 25 0.0094
127.0.0.1 - - [08/Oct/2011 19:54:43] "GET/HTTP/1.1" 200 25 0.0098
/home/zcdny/repo/test/route.rb:4: warning: already initialized constant C
127.0.0.1 - - [08/Oct/2011 19:54:55] "GET/HTTP/1.1" 200 25 0.0003
127.0.0.1 - - [08/Oct/2011 19:54:55] "GET/HTTP/1.1" 200 25 0.0006
/home/zcdny/repo/test/route.rb:4: warning: already initialized constant C
127.0.0.1 - - [08/Oct/2011 19:54:56] "GET/HTTP/1.1" 200 25 0.0003
127.0.0.1 - - [08/Oct/2011 19:54:56] "GET/HTTP/1.1" 200 25 0.0005
Eidt
固定route.rb
require 'sinatra'
configure do
C = "this is a test for constant"
end
get '/' do
"Hello World!"
end
現在的文件時,服務器將不再警告常數初始化。 但服務器的日誌仍然出現雙'GET'需要, 我只是希望它需要一個到所有需要的客戶,這是我的問題,如何解決它。
在此先感謝。
我不會發生什麼事,有意義的sinatra需要兩次,看到的問題,我編輯它。 – coolesting
儘管如此,我的答案依然如此:警告指出您在route.rb的第4行中設置了兩次常量,您將這樣做。您的文件只加載一次,但是該行會在每個請求中執行。 –
實際上,我將定義的常量添加到配置塊中,不會顯示錯誤消息。但我真的知道爲什麼Sinatra需要種子兩次需要每次都有動作。 – coolesting