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

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

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:

  1. Bundle complete! 15 Gemfile dependencies, 73 gems now installed.
  2. Use `bundle info [gemname]` to see where a bundled gem is installed.
  3. run bundle binstubs bundler
  4. rails importmap:install
  5. C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:442:in `validate_ruby!': Your
  6. Ruby version is 3.2.2, but your Gemfile specified 3.1.2 (Bundler::RubyVersionMi smatch)
  7. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:417:in `validate _runtime!'
  8. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler.rb:165:in `setup'
  9. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `block in <top (required)>'
  10. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:159:in `with_level '
  11. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:111:in `silence'
  12. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `<top (required )>'
  13. from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req uire.rb>:85:in `require'
  14. from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req uire.rb>:85:in `require'
  15. from D:/railsfriends/friends/config/boot.rb:3:in `<top (required)>'
  16. from bin/rails:3:in `require_relative'
  17. from bin/rails:3:in `<main>'
  18. rails turbo:install stimulus:install
  19. C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:442:in `validate_ruby!': Your
  20. Ruby version is 3.2.2, but your Gemfile specified 3.1.2 (Bundler::RubyVersionMi smatch)
  21. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/definition.rb:417:in `validate _runtime!'
  22. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler.rb:165:in `setup'
  23. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `block in <top (required)>'
  24. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:159:in `with_level '
  25. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/ui/shell.rb:111:in `silence'
  26. from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/setup.rb:23:in `<top (required )>'
  27. from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req uire.rb>:85:in `require'
  28. from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_req uire.rb>:85:in `require'
  29. from D:/railsfriends/friends/config/boot.rb:3:in `<top (required)>'
  30. from bin/rails:3:in `require_relative'
  31. 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:

  1. Bundle complete! 15 Gemfile dependencies, 73 gems now installed.
  2. Use `bundle info [gemname]` to see where a bundled gem is installed.
  3. run bundle binstubs bundler
  4. rails importmap:install
  5. Add Importmap include tags in application layout
  6. insert app/views/layouts/application.html.erb
  7. Create application.js module as entrypoint
  8. create app/javascript/application.js
  9. Use vendor/javascript for downloaded pins
  10. create vendor/javascript
  11. create vendor/javascript/.keep
  12. Ensure JavaScript files are in the Sprocket manifest
  13. append app/assets/config/manifest.js
  14. Configure importmap paths in config/importmap.rb
  15. create config/importmap.rb
  16. Copying binstub
  17. create bin/importmap
  18. rails turbo:install stimulus:install
  19. Import Turbo
  20. append app/javascript/application.js
  21. Pin Turbo
  22. append config/importmap.rb
  23. Create controllers directory
  24. create app/javascript/controllers
  25. create app/javascript/controllers/index.js
  26. create app/javascript/controllers/application.js
  27. create app/javascript/controllers/hello_controller.js
  28. Import Stimulus controllers
  29. append app/javascript/application.js
  30. Pin Stimulus
  31. Appending: pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true"
  32. append config/importmap.rb
  33. Appending: pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
  34. append config/importmap.rb
  35. Pin all controllers
  36. Appending: pin_all_from "app/javascript/controllers", under: "controllers"
  37. append config/importmap.rb
  38. 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:

确定