为什么 Rails 不会在每次请求时刷新类(尽管有配置)? [英] Why does Rails not refresh classes on every request (despite configuration)?

查看:38
本文介绍了为什么 Rails 不会在每次请求时刷新类(尽管有配置)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始每次更改代码时都必须重新启动开发服务器.我的 development.rb 文件仍然有这一行:

config.cache_classes = false

我尝试使用调试器验证该值是否存在.为此,我将配置设置为 environment.rb 中的全局变量:

$my_initializer = Rails::Initializer.run do |config|...结束

然后我在我的一个控制器中放置了一个 debugger 行,这样我就可以做到这一点:

(rdb:2) $my_initializer.configuration.cache_classes假

这样就消除了 cache_classes 的值在其他地方被设置为 true 的可能性.我已经尝试使用 Mongrel 和 WEBrick,但它仍然会发生.

还有什么可能导致 Rails 没有在每次请求时重新加载我的代码?

我正在运行:杂种 1.1.5
WEBrick 1.3.1
Rails 2.3.8
红宝石 1.8.7 p253

在@Daemin 的建议下,我检查了我的文件的 mtime 是否在我将它们保存在文本编辑器 (Textmate) 中时实际上正在更新

merced:controllers lance$ ls -l people_controller.rb-rwxr-xr-x 1 lance 员工 2153 Act 10 18:01 people_controller.rb

然后我进行了更改并保存了文件:

merced:controllers lance$ ls -l people_controller.rb-rwxr-xr-x@ 1 lance 员工 2163 Oct 11 12:03 people_controller.rb

所以 mtime 没有问题.

解决方案

如果其他人有这个问题,解决方案是这样的:config.threadsafe! 必须在 config.cache_classes 之前.像这样重新排序以修复它:

<预><代码>...配置线程安全!config.cache_classes = false...

答案来自:Rails:cache_classes =>false 仍然缓存

I recently started having to restart my development server every time I change my code. My development.rb file still has this line:

config.cache_classes = false

I tried using the debugger verify that this value has stuck around. To do this I set my configuration to a global variable in environment.rb:

$my_initializer = Rails::Initializer.run do |config|
  ...
end

then I put a debugger line in one of my controllers so I could do this:

(rdb:2) $my_initializer.configuration.cache_classes
false

So that eliminated the possibility that the value of cache_classes was getting set to true somewhere else. I've tried using both Mongrel and WEBrick and it still happens.

What else might be causing Rails not to reload my code with every request?

I am running: Mongrel 1.1.5
WEBrick 1.3.1
Rails 2.3.8
Ruby 1.8.7 p253

EDIT: at @Daemin 's suggestion I checked that the mtime of my files are are actually getting updated when I save them in my text editor (Textmate)

merced:controllers lance$ ls -l people_controller.rb 
-rwxr-xr-x  1 lance  staff  2153 Act 10 18:01 people_controller.rb

Then I made a change and saved the file:

merced:controllers lance$ ls -l people_controller.rb 
-rwxr-xr-x@ 1 lance  staff  2163 Oct 11 12:03 people_controller.rb

So it's not a problem with the mtimes.

解决方案

If anyone else has this problem the solution was the order: config.threadsafe! has to come before config.cache_classes. Reorder it like this to fix it:

...
config.threadsafe!
config.cache_classes = false
...

answer from: Rails: cache_classes => false still caches

这篇关于为什么 Rails 不会在每次请求时刷新类(尽管有配置)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆