Rails 不会在 FreeBSD 9.1 中对每个请求重新加载控制器和助手

Rails does not reload controllers, helpers on each request in FreeBSD 9.1

我检测到 rails 的奇怪行为。请多多指教!

例如我有这样的代码:

def new
  raise
end

我以开发模式启动 rails 服务器。 在浏览器中点击刷新并查看

RuntimeError in AuthenticationController#new

好的。我这样用 "raise" 注释掉行:

def
  # raise
end

在浏览器中点击刷新,但我再次看到如上所示的错误。即使在浏览器中我看到代码被注释掉 "raise".

我的猜测是控制器和助手等正在重新加载,但 rails returns 缓存结果。

config/environments/development.rb:

Rails.application.configure do
  # BetterErrors::Middleware.allow_ip! '192.168.78.0/16'

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = false

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

  # Asset digests allow you to set far-future HTTP expiration dates on all assets,
  # yet still be able to expire them through the digest params.
  config.assets.digest = true

  # Adds additional error checking when serving assets at runtime.
  # Checks for improperly declared sprockets dependencies.
  # Raises helpful error messages.
  config.assets.raise_runtime_errors = false

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true
end

我如何启动服务器:

=> Booting Puma
=> Rails 4.2.1.rc3 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Puma 2.11.1 starting...
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://0.0.0.0:3000

有什么建议吗

更新 1. 此问题在 Ubuntu 14.04 中不存在,但在 FreeBSD 9.1 中存在。

我已经创建了简单的应用程序,并首先在 FreeBSD 中对其进行了测试(同样的问题),然后在 Ubuntu 中进行了测试(没问题)。

你能帮我建议一下如何在 FreeBSD 9.1 上处理这个问题吗?

请检查您是否真的运行开发模式的应用程序,而不是生产模式。

同时检查您 /config/environments/development.rb 以查看缓存 类 是否关闭:

config.cache_classes = false

这篇 other post 可能会对您有所帮助。

我终于想通了!

这是关于 rails 追踪器的回答:https://github.com/rails/rails/issues/16678

如果您使用 VirtualBox + NFS,由于 Rails 4.

中的一些更改,您必须同步主机和客户端之间的时间

与 Rails 5 + Vagrant + Ubuntu 16 有同样的问题。None 其他解决方案有效(我的访客和主机时间同步)。

唯一对我有用的是注释掉 config/environments/development.rb 中的以下行:

config.file_watcher = ActiveSupport::EventedFileUpdateChecker

我想我会 post 这样做,以防其他人像我一样因类似问题访问此页面。

Rails.application.reloader.reload!

在 rails 控制台中找到 method(:reload!).source

(rails 6)