ruby-on-rails - Ruby 3.0.1,Rails 6 puma 服务器连接未建立
问题描述
我最近将一个 rails 应用程序升级到 ruby 3.0.1 和 rails 6,我已经安装了 Puma 并设置了默认配置,启动了服务器,但是,我得到了以下信息。
=> Booting Puma
=> Rails 6.1.3.2 application starting in development
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.3.2 (ruby 3.0.1-p64) ("Sweetnighter")
* Min threads: 5
* Max threads: 5
* Environment: development
* PID: 9665
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
Use Ctrl-C to stop
这是puma.rb
配置
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum, this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count
# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
#
port ENV.fetch("PORT") { 3000 }
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory. If you use this option
# you need to make sure to reconnect any threads in the `on_worker_boot`
# block.
#
# preload_app!
# The code in the `on_worker_boot` will be called if you are using
# clustered mode by specifying a number of `workers`. After each worker
# process is booted this block will be run, if you are using `preload_app!`
# option you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, Ruby
# cannot share connections between processes.
#
# on_worker_boot do
# ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
# end
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
我跟踪了日志,得到以下信息
Being able to do this is deprecated. Autoloading during initialization is going
to be an error condition in future versions of Rails.
Reloading does not reboot the application, and therefore code executed during
initialization does not run again. So, if you reload Secretor, for example,
the expected changes won't be reflected in that stale Class object.
This autoloaded constant has been unloaded.
In order to autoload safely at boot time, please wrap your code in a reloader
callback this way:
Rails.application.reloader.to_prepare do
# Autoload classes and modules needed at boot time here.
end
That block runs when the application boots, and every time there is a reload.
For historical reasons, it may run twice, so it has to be idempotent.
Check the "Autoloading and Reloading Constants" guide to learn more about how
Rails autoloads and reloads.
(called from <main> at /home/ben/code/app/config/environment.rb:5)
这是我的环境.rb
# Load the Rails application.
require_relative "application"
# Initialize the Rails application.
Rails.application.initialize!
不知道问题出在哪里,我使用的是默认配置。
编辑 应用程序.rb
require_relative 'boot'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
require 'net/http'
require 'csv'
module RailsUpgrade
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.1
config.autoloader = :zeitwerk
# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
# in config/environments, which are processed later.
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
config.time_zone = 'London'
config.log_level = :debug
config.enable_dependency_loading = true
config.eager_load_paths << Rails.root.join('lib')
config.assets.enabled = true
config.assets.version = '1.0'
config.filter_parameters << :password
config.filter_parameters << :password_confirmation
config.filter_parameters << :card_number
config.filter_parameters += [:password, :password_confirmation, :card_number]
end
end
解决方案
推荐阅读
- c++ - 如何在 GET 请求中包含 ESP8266 mac 作为 arg?
- javascript - 如何以随机时间间隔进行倒计时,停在零?
- yii2 - 如何在 YII restful GET api 上实现过滤?
- error-handling - How do I fix "may not be safely transferred across an unwind boundary" for VaList?
- php - 如何传入建立数据库();进入 PHP 中的函数
- c++ - 如何在 C++ 中从头到尾写入文件
- javascript - Aframe Text 看屏幕
- android - 生成签名 APK 失败
- android - 显示带有字母数字切换选项的数字键盘
- python - 如何在Django中使用注册的电话号码和密码登录