【问题标题】:Rails: Handling different versions of gemsRails:处理不同版本的宝石
【发布时间】:2018-10-18 20:52:46
【问题描述】:

我有一个安装了 rvm 的 rails 5.2 应用程序:

=> ruby-2.4.2 [ x86_64 ]
 * ruby-2.4.4 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

我想添加自动备份数据库的功能,所以安装了backup gem。我知道这不应该添加到GemFile,因为它的一些依赖关系相对较旧,所以我使用了命令gem install backup-v5.0.0.beta2

当我运行 gem list 时,有许多 gem 有两个版本号,例如open4 (1.3.4, 1.3.0)

当我尝试通过backup perform -t db_backup --config-file /Users/<path_to_my_rails_project>/config/Backup/config.rb 手动触发备份例程时遇到问题,这会产生错误:

[error] CLI::Error
[error] --- Wrapped Exception ---
[error] Gem::LoadError: You have already activated open4 1.3.0, but your Gemfile requires open4 1.3.4. Prepending `bundle exec` to your command may solve this.

按照错误消息中的引导,bundle exec backup perform -t db_backup --config-file /Users/<path_to_my_rails_project>/config/Backup/config.rb 产生错误:

/Users/<my_username>/.rvm/gems/ruby-2.4.2/gems/bundler-1.16.6/lib/bundler/rubygems_integration.rb:462:in `block in replace_bin_path': can't find executable backup for gem backup. backup is not currently included in the bundle, perhaps you meant to add it to your Gemfile? (Gem::Exception)

请您告知我应该如何安装 backup gem 并运行任务,而不会因为安装了相同 gem 的不同版本而出现错误

【问题讨论】:

    标签: ruby-on-rails rubygems rvm


    【解决方案1】:

    确保您没有像这样对 gem 进行版本锁定:gem open4, '~&gt; 1.3.4'

    试试bundle update open4 backup。我也会尝试最新版本的 gem。

    另一种选择是放弃这个 gem 并尝试 https://github.com/javan/whenever 并只运行一个简单的 pg_dump,或者不使用任何 gem 并添加一个 cron 作业来创建一个 pg_dump 并在文件名中使用时间戳。

    这些问题可能很难调试,但我的方法通常是开始删除 gem 并让 bundler 自己找出它的依赖关系树。您在 Gemfile 中定义的越多,捆绑程序就越有可能出现版本不匹配,从而引发与您所看到的错误类似的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-12
      • 1970-01-01
      相关资源
      最近更新 更多