2012-05-31 226 views
3

我最近開始研究一個我從github克隆的項目。嘗試啓動rails服務器時出現語法錯誤

每次我嘗試啓動rails服務器我得到以下錯誤:

 
/Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in load': /Users/thomas/Projects/BillingMiddleware/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end (SyntaxError) 
...sion_store :cookie_store, key: '_BillingMiddleware_session' 
          ^
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:inload' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in load_dependency' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:inload' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/engine.rb:588 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/engine.rb:587:in each' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/engine.rb:587 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:30:ininstance_exec' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:30:in run' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:55:inrun_initializers' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:54:in each' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:54:inrun_initializers' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/application.rb:136:in initialize!' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:insend' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in method_missing' 
    from /Users/thomas/Projects/BillingMiddleware/config/environment.rb:5 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:inrequire' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in require' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:inload_dependency' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in require' 
    from /Users/thomas/Projects/BillingMiddleware/config.ru:4 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:ininstance_eval' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in initialize' 
    from /Users/thomas/Projects/BillingMiddleware/config.ru:1:innew' 
    from /Users/thomas/Projects/BillingMiddleware/config.ru:1 

我collegue也在致力於該項目,並似乎不啓動服務器的任何問題。他正在運行與我一樣的Ruby,Rails和WeBrick版本。

我試着改變從鍵的語法:鍵=>,這應該不是問題,雖然我運行ruby版本1.9.3。如果我作出這樣的改變,無論如何我得到一個不同的錯誤信息:

 
/Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load': /Users/thomas/Projects/BillingMiddleware/config/initializers/wrap_parameters.rb:8: syntax error, unexpected ':', expecting kEND (SyntaxError) 
    wrap_parameters format: [:json] 
         ^
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/engine.rb:588 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/engine.rb:587:in `each' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/engine.rb:587 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `run_initializers' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `send' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing' 
    from /Users/thomas/Projects/BillingMiddleware/config/environment.rb:5 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' 
    from /Users/thomas/Projects/BillingMiddleware/config.ru:4 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval' 
    from /Users/thomas/.rvm/gems/ruby-1.9.3-p194/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize' 
    from /Users/thomas/Projects/BillingMiddleware/config.ru:1:in `new' 
    from /Users/thomas/Projects/BillingMiddleware/config.ru:1 

我已經厭倦了完全拆卸和重新安裝RVM,Ruby和Rails了幾次都沒爲準。我也試過運行捆綁安裝,這沒有幫助。

有沒有人有任何想法出了什麼問題?

謝謝

回答

5

嘗試將哈希值更改爲:key =>:value語法。在Rails 3.1 Deployment to Heroku Error討論相同的錯誤和修復。 建議的臨時修補程序是: 配置/初始化/ session_store.rb

App::Application.config.session_store :cookie_store, :key => '_BillingMiddleware_session' 

配置/初始化/ wrap_parameters.rb

ActionController::Base.wrap_parameters :format => [:json] 
+0

這似乎是解決問題的快速解決方案。我只是想知道爲什麼當我運行Ruby 1.9.3時,它爲散列值的這種語法抱怨? – MalcolmDurling

+0

你仍然在你的系統中以某種方式使用ruby 1.8.7。至少你已經起來跑步了。祝你好運。 – Anil

+0

許多代碼已經提交給項目,雖然有了新的語法,但是當它爲項目的其他成員工作時,似乎毫無意義地將它們全部更改回舊語法。這是我能嘗試的其他事情嗎?當我運行紅寶石-v我得到 紅寶石1.9.3p194(2012-04-20修訂版35410)[x86_64-darwin11.3.0] 我使用RVM,當我運行rvm列表紅寶石時,我只得到= * ruby​​-1.9 .3-p194 [x86_64]我也運行rvm使用ruby-1.9.3-p194,這沒有幫助。 – MalcolmDurling

1

看起來像在修復那個之後的另一行上的散列語法。檢查config/intializers/wrap_parameters.rb,我想知道這個項目是否得到了「不」使用新語法的標誌?

+0

我已經改變都不會使用新的語法,但它再次似乎在項目中使用新的語法找到更多的例子並且抱怨它們。該項目是由我的同事自己創建的,所以我堅信它不會使用新語法。他似乎能夠在他的最後沒有問題地啓動服務器。 – MalcolmDurling

+0

你的'ruby -v'說了些什麼?你有沒有重新啓動你的控制檯選項卡也許有些奇怪的事情發生。你在獅子和他在雪豹嗎? – pjammer

+0

當我運行'ruby -v'時,它返回紅寶石1.9.3p194(2012-04-20修訂版35410)[x86_64-darwin11.3.0]。每次我執行更新或安裝了某些東西時,我都重新啓動了控制檯。是的,我們兩臺電腦都運行10.7.3。 – MalcolmDurling

相關問題