【问题标题】:Can't start old rails version (syntaxError)无法启动旧版 Rails (syntaxError)
【发布时间】:2021-07-31 01:13:11
【问题描述】:

我刚刚在我的 ubuntu 18.04 服务器上导入了一个已有 5 年历史的 rails 项目。我下载了所有要求,例如 ruby​​ 2.0.0 或 rails 3.2.22 以及所有 gem。

目前我正在尝试运行:rails app:update,这给了我以下错误(运行 rail s 时相同):

/usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/site_ruby/2.0.0/bundler/runtime.rb:81:in `require': /usr/local/rvm/gems/ruby-2.0.0-p648/gems/coverband-5.1.0/lib/coverband.rb:83: syntax error, unexpected '.' (SyntaxError)
    (Rake&.application&.top_level_tasks ...
           ^
        from /usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/site_ruby/2.0.0/bundler/runtime.rb:81:in `block (2 levels) in require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/site_ruby/2.0.0/bundler/runtime.rb:76:in `each'
        from /usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/site_ruby/2.0.0/bundler/runtime.rb:76:in `block in require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/site_ruby/2.0.0/bundler/runtime.rb:65:in `each'
        from /usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/site_ruby/2.0.0/bundler/runtime.rb:65:in `require'
        from /usr/local/rvm/rubies/ruby-2.0.0-p648/lib/ruby/site_ruby/2.0.0/bundler.rb:114:in `require'
        from /home/ project/apps/current/config/application.rb:9:in `<top (required)>'
        from /usr/local/rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.22.5/lib/rails/commands.rb:53:in `require'
        from /usr/local/rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.22.5/lib/rails/commands.rb:53:in `block in <top (required)>'
        from /usr/local/rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.22.5/lib/rails/commands.rb:50:in `tap'
        from /usr/local/rvm/gems/ruby-2.0.0-p648/gems/railties-3.2.22.5/lib/rails/commands.rb:50:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'

我在尝试运行时也遇到错误:rake migrate

rake aborted!
SyntaxError: /usr/local/rvm/gems/ruby-2.0.0-p648/gems/coverband-5.1.0/lib/coverb                                        and.rb:83: syntax error, unexpected '.'
    (Rake&.application&.top_level_tasks ...
           ^
/home/ project/apps/current/config/application.rb:9:in `<top (required)>'
/home/ project/apps/current/Rakefile:5:in `require'
/home/ project/apps/current/Rakefile:5:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p648/bin/ruby_executable_hooks:22:in `eval'
/usr/local/rvm/gems/ruby-2.0.0-p648/bin/ruby_executable_hooks:22:in `<main>'

感谢您的帮助!

【问题讨论】:

  • 宝石coverband v5.1.0released on December 31st 2020。所以这不可能是一个“5岁的应用程序”。你必须要么没有提交Gemfile.lock(所以没有记录实际使用了哪些gem版本?!),或者已经运行bundle update - 它更新了旧应用程序没有准备好的一堆依赖项.
  • 可能能够只使用 ruby​​ 2.3(它引入了 &amp;. 安全导航语法)并发现它工作正常,或者你可能还会遇到当您尝试更新 5 年的依赖项时,还会遇到更多问题。
  • 我的建议是,如果你不能用 ruby​​ 2.3 快速完成这项工作,那么首先将你的更改恢复到 Gemfile.lock(即完全按照它的方式运行旧应用程序以前使用过),然后一次只更新较小的依赖集。

标签: ruby-on-rails ruby rake


【解决方案1】:

在 Ruby 2.3.0 中添加了安全导航运算符 (&amp;.)。

通过运行rails app:update 更改的一些代码使用它。

因此,您首先需要将 Ruby 版本升级到 2.3.0+。


Rails upgrades and Ruby version requirements

【讨论】:

    猜你喜欢
    • 2018-10-18
    • 2018-04-03
    • 1970-01-01
    • 1970-01-01
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多