簡體   English   中英

Ruby on Rails:如何修復服務器啟動錯誤?

[英]Ruby on Rails: How do I fix the server starting error?

我正在嘗試啟動一個 Rails 項目並嘗試最初啟動服務器以查看它是否有效。 但是,每當我通過在終端中輸入rails s來啟動它時,我的瀏覽器中的localhost:3000會彈出以下錯誤:

Puma caught this error: Error loading the 'postgresql' Active Record adapter. Missing a gem it depends on? can't activate pg (~> 1.1), already activated pg-0.21.0. Make sure all dependencies are added to Gemfile. (LoadError)
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/bundler/rubygems_integration.rb:408:in `block (2 levels) in replace_gem'
/Library/Ruby/Gems/2.6.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:3:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
/Library/Ruby/Gems/2.6.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1205:in `resolve_pool_config'
/Library/Ruby/Gems/2.6.0/gems/activerecord-6.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1046:in `establish_connection'
/Library/Ruby/Gems/2.6.0/gems/activerecord-6.1.1/lib/active_record/connection_handling.rb:52:in `establish_connection'
/Library/Ruby/Gems/2.6.0/gems/activerecord-6.1.1/lib/active_record/railtie.rb:222:in `block (2 levels) in <class:Railtie>'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:51:in `each'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/Library/Ruby/Gems/2.6.0/gems/activerecord-6.1.1/lib/active_record/base.rb:315:in `<module:ActiveRecord>'
/Library/Ruby/Gems/2.6.0/gems/activerecord-6.1.1/lib/active_record/base.rb:15:in `<main>'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/Library/Ruby/Gems/2.6.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/Library/Ruby/Gems/2.6.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
/Library/Ruby/Gems/2.6.0/gems/activerecord-6.1.1/lib/active_record/query_cache.rb:31:in `run'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/execution_wrapper.rb:28:in `before'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:427:in `block in make_lambda'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:198:in `block (2 levels) in halting'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:604:in `block (2 levels) in default_terminator'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:603:in `catch'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:603:in `block in default_terminator'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:199:in `block in halting'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:512:in `block in invoke_before'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:512:in `each'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:512:in `invoke_before'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/callbacks.rb:105:in `run_callbacks'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/execution_wrapper.rb:111:in `run!'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/execution_wrapper.rb:73:in `block in run!'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/execution_wrapper.rb:70:in `tap'
/Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.1/lib/active_support/execution_wrapper.rb:70:in `run!'
/Library/Ruby/Gems/2.6.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/executor.rb:12:in `call'
/Library/Ruby/Gems/2.6.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/static.rb:24:in `call'
/Library/Ruby/Gems/2.6.0/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
/Library/Ruby/Gems/2.6.0/gems/actionpack-6.1.1/lib/action_dispatch/middleware/host_authorization.rb:98:in `call'
/Library/Ruby/Gems/2.6.0/gems/rack-mini-profiler-2.3.0/lib/mini_profiler/profiler.rb:373:in `call'
/Library/Ruby/Gems/2.6.0/gems/webpacker-5.2.1/lib/webpacker/dev_server_proxy.rb:25:in `perform_request'
/Library/Ruby/Gems/2.6.0/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
/Library/Ruby/Gems/2.6.0/gems/railties-6.1.1/lib/rails/engine.rb:539:in `call'
/Library/Ruby/Gems/2.6.0/gems/puma-5.1.1/lib/puma/configuration.rb:246:in `call'
/Library/Ruby/Gems/2.6.0/gems/puma-5.1.1/lib/puma/request.rb:76:in `block in handle_request'
/Library/Ruby/Gems/2.6.0/gems/puma-5.1.1/lib/puma/thread_pool.rb:337:in `with_force_shutdown'
/Library/Ruby/Gems/2.6.0/gems/puma-5.1.1/lib/puma/request.rb:75:in `handle_request'
/Library/Ruby/Gems/2.6.0/gems/puma-5.1.1/lib/puma/server.rb:431:in `process_client'
/Library/Ruby/Gems/2.6.0/gems/puma-5.1.1/lib/puma/thread_pool.rb:145:in `block in spawn_thread'

這是我的 GemFile:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.3'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.1.1'
# Use sqlite3 as the database for Active Record
# gem 'sqlite3', '~> 1.4'

# postgres database support
gem 'pg', '~> 0.21'

# User authentication
gem 'devise'

# Use Puma as the app server
gem 'puma', '~> 5.0'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
gem 'bootstrap-sass', '~> 3.4.1'

# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 5.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
# gem 'turbolinks', '~> 5'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Active Storage variant
# gem 'image_processing', '~> 1.2'

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.4', require: false

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end

group :development do
  # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
  gem 'web-console', '>= 4.1.0'
  # Display performance information such as SQL time and flame graphs for each request in your browser.
  # Can be configured to work on production as well see: https://github.com/MiniProfiler/rack-mini-profiler/blob/master/README.md
  gem 'rack-mini-profiler', '~> 2.0'
  gem 'listen', '~> 3.3'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
end

group :test do
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '>= 3.26'
  gem 'selenium-webdriver'
  # Easy installation and use of web drivers to run system tests with browsers
  gem 'webdrivers'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

如果對此有任何解決方案,將不勝感激。

加載“postgresql”Active Record 適配器時出錯。 缺少它所依賴的寶石? 無法激活 pg (~> 1.1),已激活 pg-0.21.0。

存在依賴沖突。 Active Record 需要 pg ~> 1.1 但你的 Gemfile 需要 pg ~> 0.21。

除非你有很好的理由阻止 pg gem,否則將你的 Gemfile 更改為不再需要特定版本的 pg。 您沒有直接使用 pg gem,讓其他 gem 的要求決定所需的 pg 版本。

gem 'pg'

通常,您的 Gemfile 需要非常特定版本的 gems,而且它可能不需要; 你真的需要 bootstrap-sass 的 3.4.1 版本嗎? 過於具體會導致更多這樣的依賴沖突。

依靠Gemfile.lock來凍結依賴關系以保持穩定性。 依靠測試來確保升級后一切仍然有效。 在出現特定問題時保留版本限制,並使其盡可能寬容。

例如,將 Rails 固定到~> 6~> 6.1很好,因為升級 Rails 可能非常重要。 將它固定到~> 6.1.1有點多,因為 6.1.x 只是錯誤修復版本,應該可以很好地升級。

OTOH 根本沒有必要固定美洲獅。 這是您不會直接引用的 web 服務器。 讓 rails 和 rack 管理它們對 puma 的依賴。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM