0

我有一个构建在我的测试环境上的 rails 应用程序。

ruby -v  => 1.9.3p194    
rails -v => 3.2.12    
gem -v   => 1.8.23

在我希望部署到的服务器上,输出如下:

ruby -v  => 1.9.3p0
rails -v => 3.2.12
gem -v   => 1.8.15

我已经开始全新安装服务器,但我无法让服务器版本的 ruby​​ 和 gem 匹配。

此外,当我在服务器上运行 rails s 时(只是为了测试),这是失败的输出:

rails s
=> Booting WEBrick
=> Rails 3.2.12 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/var/lib/gems/1.8/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in `load': /var/www/New/confed ':', expecting kEND (SyntaxError)
  match '/about',   to: 'static_pages#about'
                       ^
/var/www/New/config/routes.rb:6: syntax error, unexpected ':', expecting kEND
  match '/cv',          to: 'static_pages#cv'
                           ^
        from /var/lib/gems/1.8/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in `load'
        from /var/lib/gems/1.8/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:236:in `load_dependency'
        from /var/lib/gems/1.8/gems/activesupport-3.2.12/lib/active_support/dependencies.rb:245:in `load'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:40:in `load_paths'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:40:in `each'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:40:in `load_paths'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:16:in `reload!'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:26:in `updater'
        from /var/lib/gems/1.8/gems/activesupport-3.2.12/lib/active_support/file_update_checker.rb:78:in `call'
        from /var/lib/gems/1.8/gems/activesupport-3.2.12/lib/active_support/file_update_checker.rb:78:in `execute'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:27:in `updater'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/application/finisher.rb:66
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `instance_exec'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/initializable.rb:30:in `run'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/initializable.rb:55:in `run_initializers'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `each'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/initializable.rb:54:in `run_initializers'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/application.rb:136:in `initialize!'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `send'
        from /var/lib/gems/1.8/gems/railties-3.2.12/lib/rails/railtie/configurable.rb:30:in `method_missing'
        from /var/www/New/config/environment.rb:5
        from /var/www/New/config.ru:3:in `require'
        from /var/www/New/config.ru:3
        from /var/lib/gems/1.8/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
        from /var/lib/gems/1.8/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
        from /var/www/New/config.ru:0:in `new'
        from /var/www/New/config.ru:0

我查看了我的测试系统,但我没有/var/lib/gems/1.8我只有/var/lib/gems/1.9.1

4

1 回答 1

2

从您的堆栈跟踪来看,实际上您运行的是 Ruby 1.8,它不支持简化的哈希语法symbol: value,而 1.8 只有:symbol => value.

您可以使用rvmrbenv来管理多个 ruby​​ 版本。rbenv在使用 Rails 时,imo 是两者中的佼佼者。


回答瑞恩关于我为什么认为rbenv > rvm是基于个人感受的问题。我发现它rbenv易于使用、易于理解和概念化它是如何工作的,而且我还没有遇到让我失望的场景。此外,源代码可读性很强,这使我的一次配置尝试变得容易。

于 2013-03-03T23:57:42.733 回答