天天看點

詭異的"already initialized constant OPTIONS"及解決方案

最近要為公司一個程式加資料統計代碼。在Ubuntu環境下checkout下整個程式,發現無法打開server,出錯資訊如下:

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)

=> Rails application starting on http://0.0.0.0:3000

=> Call with -d to detach

=> Ctrl-C to shutdown server

** Ruby version is not up-to-date; loading cgi_multipart_eof_fix

** Starting Mongrel listening at 0.0.0.0:3000

** Starting Rails with development environment...

ActiveScaffold: extending RESTful routes for students

ActiveScaffold: extending RESTful routes for student_profiles

ActiveScaffold: extending RESTful routes for discount_codes

ActiveScaffold: extending RESTful routes for trainers

ActiveScaffold: extending RESTful routes for trainer_profiles

ActiveScaffold: extending RESTful routes for certified_modules

ActiveScaffold: extending RESTful routes for scenarios

Exiting

/var/lib/gems/1.8/gems/rails-1.2.4/lib/commands/servers/mongrel.rb:15: warning: already

initialized constant OPTIONS

/var/lib/gems/1.8/gems/rails-1.2.4/lib/commands/servers/mongrel.rb:18: undefined method

`options' for []:Array (NoMethodError)

from /usr/lib/ruby/1.8/rubygems/custom_require.rb:33:in `gem_original_require'

from /usr/lib/ruby/1.8/rubygems/custom_require.rb:33:in `require'

from /var/lib/gems/1.8/gems/activesupport-

1.4.3/lib/active_support/dependencies.rb:495:in `require'

from /var/lib/gems/1.8/gems/activesupport-

1.4.3/lib/active_support/dependencies.rb:342:in `new_constants_in'

from /var/lib/gems/1.8/gems/activesupport-

1.4.3/lib/active_support/dependencies.rb:495:in `require'

from /var/lib/gems/1.8/gems/rails-1.2.4/lib/commands/server.rb:39

from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'

from /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'

from script/server:3

開始以為是環境出錯,但發現建立的空項目可以運作。

于是搜尋:"warning: already initialized constant OPTIONS"

得到

http://blog.1sters.com/?action=show&id=32

http://www.dansketcher.com/2007/05/07/warning-already-initialized-constant-options/

解決方法都說是缺少app中使用的gem,但檢視environment.rb,安裝所有require,server依然啟動不起來。

搜尋:"undefined method `options' for []:Array (NoMethodError)"

得到:

http://bpdp.wordpress.com/2007/08/27/what-does-mongrelrb15-warning-already-initialized-constant

-options-means/

作者的解決方案如下:

"All I have to do is remove all of the plugins (I just move it to directory

$RAILS_ROOT/tmp/plugins which I created myself) and then start move it one by one to

$RAILS_ROOT/vendor/plugins and test it using $RAILS_ROOT/script/server webrick.Then I found that

activemerchant is my problem. I need builder gem.It is all easy but the error messages was

really a mess :)"

按照他的方法,我把$RAILS_ROOT/vendor/plugins中的所有檔案剪切出來再逐一拷貝回去并測試伺服器,最終

發現是tzinfo_timezone導緻的出錯。

安裝tzinfo_timezone,啟動server,問題解決。

簡單的問題,不過真是“ error messages was really a mess :)”

順便說下,

http://blog.1sters.com/?action=show&id=32中說在environment.rb添加“require ‘nonexistingfile’”

可啟動伺服器,實際上這是複現這個錯誤的方法。

找可以運作的環境,檢視安裝的gem list,把缺少的安裝一遍就行。上面好笨~~~