【问题标题】:Rails does not reload controllers, helpers on each request in FreeBSD 9.1Rails 不会在 FreeBSD 9.1 中的每个请求上重新加载控制器和助手
【发布时间】:2015-05-06 21:07:31
【问题描述】:

我检测到导轨的奇怪行为。请给我一些建议!

例如我有这样的代码:

def new
  raise
end

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

AuthenticationController 中的 RuntimeError#new

好的。我像这样用“raise”注释掉一行:

def
  # raise
end

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

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

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 上处理这个问题吗?

【问题讨论】:

  • 作为问题发布在 Rails 跟踪器上:github.com/rails/rails/issues/19277
  • 好的。我想通了。这是 NFS 问题。我不知道必须设置哪些配置选项,但如果我使用本地应用程序一切正常。

标签: ruby-on-rails ruby-on-rails-4 freebsd ruby-on-rails-4.2


【解决方案1】:

Rails 5 + Vagrant + Ubuntu 16 也有同样的问题。其他解决方案都不起作用(我的访客和主机时间已同步)。

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

config.file_watcher = ActiveSupport::EventedFileUpdateChecker

我想我会发布这个,以防其他人像我一样因为类似的问题访问此页面。

【讨论】:

  • 同样的问题,我也从 gemfile 中删除 gem listen
  • 相同的设置,我的 vagrant/mac 时间已经同步,所以接受的解决方案没有帮助。但是这个做到了,谢谢!
  • Rails 5 给 Vagrant 用户带来了几个问题,Rails 团队并不认为这是一个问题,正如this ticket 中所指出的那样——也许如果更多人抱怨 vagrant 相关问题,团队会理解的不是一种晦涩难懂的发展方式。
  • 这也是我的解决方法,但我不是流浪者。我在 OS X 上使用本机 docker beta(截至 2017 年 6 月 27 日),我所有的 rails 4.x 应用程序都可以使用此设置,除了我在 rails 5 上启动的这个新应用程序。注释掉 EventedFileUpdateChecker 来自我的开发配置,它现在可以工作了。
  • 我认为禁用此“功能”也解决了我在 Docker OS X 上遇到的问题,我将更新控制器中的代码,但更改未注册,因此我必须完全重新启动 docker 容器以运行我的新控制器代码。非常令人沮丧。到目前为止,它运作良好。如果这能解决问题,那将是一个巨大的帮助
【解决方案2】:

我终于明白了!

这是关于 Rails 跟踪器的答案:https://github.com/rails/rails/issues/16678

如果您使用 VirtualBox + NFS,由于 Rails 4 中的一些更改,您必须在主机和客户端之间同步时间。

【讨论】:

    【解决方案3】:

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

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

    config.cache_classes = false
    

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

    【讨论】:

    • 嘿,拉斐尔!谢谢回复。我已经用 development.rb 更新了我的问题,并证明我使用了服务器的开发模式。
    • 谢谢,当其他几个答案没有时,这救了我!!
    【解决方案4】:
    Rails.application.reloader.reload!
    

    在 Rails 控制台中使用 method(:reload!).source 找到。

    (轨道 6)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-08
      • 1970-01-01
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多