我创建新的Rails应用程序(rails new name_project)时遇到了错误。

huangapple go评论74阅读模式
英文:

I got an error while creating a new Rails app (rails new name_project)

问题

It looks like you've successfully resolved the issue by updating the Ruby version in your project's Gemfile to "3.2.2". Everything should be working normally now with the updated Ruby version. If you encounter any further issues, feel free to ask for assistance.

英文:

So I installed Ruby and Rails through this video (https://www.youtube.com/watch?v=fmyvWz5TUWg&t=9163s&ab_channel=freeCodeCamp.org) and I was making a new Rails app by using the command rails new <name of the project>. At the end, the app is created, but there are these errors at the end:

Bundle complete! 15 Gemfile dependencies, 73 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle binstubs bundler
       rails  importmap:install
C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:442:in `validate_ruby!': Your                                                                                                                                 
Ruby version is 3.2.2, but your Gemfile specified 3.1.2 (Bundler::RubyVersionMi                                                                                                                                  smatch)
from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:417:in `validate                                                                                                                                  _runtime!'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler.rb:165:in `setup'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `block in <top                                                                                                                                   (required)>'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:159:in `with_level                                                                                                                                  '
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:111:in `silence'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `<top (required                                                                                                                                  )>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req                                                                                                                                  uire.rb>:85:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req                                                                                                                                  uire.rb>:85:in `require'
        from D:/railsfriends/friends/config/boot.rb:3:in `<top (required)>'
        from bin/rails:3:in `require_relative'
        from bin/rails:3:in `<main>'
       rails  turbo:install stimulus:install

C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:442:in `validate_ruby!': Your                                                                                                                                   
Ruby version is 3.2.2, but your Gemfile specified 3.1.2 (Bundler::RubyVersionMi                                                                                                                                  smatch)
from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:417:in `validate                                                                                                                                  _runtime!'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler.rb:165:in `setup'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `block in <top                                                                                                                                   (required)>'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:159:in `with_level                                                                                                                                  '
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:111:in `silence'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `<top (required                                                                                                                                  )>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req                                                                                                                                  uire.rb>:85:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req                                                                                                                                  uire.rb>:85:in `require'
        from D:/railsfriends/friends/config/boot.rb:3:in `<top (required)>'
        from bin/rails:3:in `require_relative'
        from bin/rails:3:in `<main>'

It seems like this error is about the version of ruby, but what should I do to resolve this? Would this error affect me in any way?

EDIT

I went to the Gemfile of the project, and changed from ruby "3.1.2" to ruby "3.2.2", then deleted the whole project and create a new project again using rails new <project_name>. And then I got this:

Bundle complete! 15 Gemfile dependencies, 73 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle binstubs bundler
       rails  importmap:install
Add Importmap include tags in application layout
      insert  app/views/layouts/application.html.erb
Create application.js module as entrypoint
      create  app/javascript/application.js
Use vendor/javascript for downloaded pins
      create  vendor/javascript
      create  vendor/javascript/.keep
Ensure JavaScript files are in the Sprocket manifest
      append  app/assets/config/manifest.js
Configure importmap paths in config/importmap.rb
      create  config/importmap.rb
Copying binstub
      create  bin/importmap
       rails  turbo:install stimulus:install
Import Turbo
      append  app/javascript/application.js
Pin Turbo
      append  config/importmap.rb
Create controllers directory
      create  app/javascript/controllers
      create  app/javascript/controllers/index.js
      create  app/javascript/controllers/application.js
      create  app/javascript/controllers/hello_controller.js
Import Stimulus controllers
      append  app/javascript/application.js
Pin Stimulus
Appending: pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true"
      append  config/importmap.rb
Appending: pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
      append  config/importmap.rb
Pin all controllers
Appending: pin_all_from "app/javascript/controllers", under: "controllers"
      append  config/importmap.rb
Run turbo:install:redis to switch on Redis and use it in development for turbo streams

Now when I go check for the Gemfile of this newly created project, it now has ruby "3.2.2". So is everything working normal now?

答案1

得分: 1

只返回翻译好的部分:

"Well the easy answer is just to say you can either change the version requirement in Gemfile, or else install the version that Gemfile is specifying."
"简单的答案是要么更改Gemfile中的版本要求,要么安装Gemfile指定的版本。"

"However, I strongly urge you to remove your ruby installation, install a ruby version manager (RVM, or probably RBenv is the more popular these days) and manage your ruby installations this way. It's much easier to do it early in your Ruby adventure than later."
"然而,我强烈建议您卸载您的Ruby安装,安装一个Ruby版本管理器(RVM,或者现在可能更流行的是RBenv),以这种方式管理您的Ruby安装。在您的Ruby之旅早期进行这样的操作比以后要容易得多。"

英文:

Well the easy answer is just to say you can either change the version requirement in Gemfile, or else install the version that Gemfile is specifying.

However, I strongly urge you to remove your ruby installation, install a ruby version manager (RVM, or probably RBenv is the more popular these days) and manage your ruby installations this way. It's much easier to do it early in your Ruby adventure than later.

huangapple
  • 本文由 发表于 2023年7月6日 21:05:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629161.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定