【问题标题】:Can't generate User Model in Rails无法在 Rails 中生成用户模型
【发布时间】:2021-03-29 17:38:18
【问题描述】:

在 MimeMagic 依赖失败后,我现在无法在 Rails 中生成模型。尝试在 rails 中生成用户模型后,我收到以下警告消息和堆栈跟踪错误

rails generate model User email:string 
password_digest:string
Warning: the running version of Bundler (2.2.3) is 
older than the version that created the lockfile 
(2.2.15). We suggest you to upgrade to the version 
that created the lockfile by running `gem install 
bundler:2.2.15`.

但是,我的 Gemfile 已更新到 2.2.15,我再次运行 bundle install 无济于事。

这是该警告之后的堆栈跟踪错误的一部分:

/Users/shmeadyy/Desktop/Projects/scheduled_tweets/vendor/bundle/ruby/3.0.0/gems/msgpack-1.4.2/lib/msgpack.rb:8:in `require': incompatible library version - /Users/shmeadyy/Desktop/Projects/scheduled_tweets/vendor/bundle/ruby/3.0.0/gems/msgpack-1.4.2/lib/msgpack/msgpack.bundle (LoadError)
        from /Users/shmeadyy/Desktop/Projects/scheduled_tweets/vendor/bundle/ruby/3.0.0/gems/msgpack-1.4.2/lib/msgpack.rb:8:in `<top (required)>'
        from /Users/shmeadyy/Desktop/Projects/scheduled_tweets/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/store.rb:4:in `require'
        from /Users/shmeadyy/Desktop/Projects/scheduled_tweets/vendor/bundle/ruby/3.0.0/gems/bootsnap-1.7.2/lib/bootsnap/load_path_cache/store.rb:4:in `block in <top (required)>'

【问题讨论】:

  • 您是否尝试删除 gemfile.lock 并使用 bundle install 重新生成它?
  • 是的,试了几次都没有成功。我不明白发生了什么,因为当我检查版本号时,我的机器上有最新版本的捆绑程序,当我执行新的bundle install 时,它说它已与最新版本捆绑在一起。

标签: ruby-on-rails ruby rubygems


【解决方案1】:

用于生成 Gemfile 的捆绑器是全局安装在您的 ruby​​ gems 目录中的捆绑器。

gem environment

gem list

将为您提供有关当前 ruby​​ 和 gems 安装的更多信息。

您可能将旧版本的 bundler 添加到 gemfile 中,并使用 bundle 命令切换到旧版本。

您可以尝试通过运行提示来更新捆绑器的全局版本

gem install bundler:2.2.15

在我看来,您应该从 gemfile 中删除 bundler 条目,因为每次您使用 bundle 命令时,它都会不必要地切换回旧版本。

【讨论】:

  • 当我查看我的gem list 时,我可以看到我有bundler (2.2.15, 2.2.5)。因此,如果我从我的 Gemfile.lock 中删除 BUNDLED WITH 2.2.15 - 会有帮助吗?我注意到在我的 Gemfile.lock 中我有 bundler (&gt;= 1.15.0) - 这是问题所在吗?
  • 我宁愿使用gem install bundler:2.2.15 并在用于生成 Gemfile.lock 的同一版本的捆绑程序上进行操作。你有什么理由宁愿坚持旧版本吗?您在常规 Gemfile 中有 gem 'bundler' 条目吗?
  • 我不在乎我使用的是什么捆绑器版本。在这一点上,我已经多年没有在 Rails 工作了,所以我真的不知道如何删除旧版本?删除就这么简单吗? Gemfile 中没有捆绑器条目。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-02
  • 1970-01-01
  • 1970-01-01
  • 2014-09-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多