简体   繁体   English

在Mac OS X Mountain Lion上升级到Ruby 2.0后,Rails缓存我的代码

[英]Rails caching my code after upgrading to Ruby 2.0 on Mac OS X Mountain Lion

Rails 3.2.13 is caching my helper modules, controllers, and other ruby code in Development mode after upgrading to Ruby 2.0 from Ruby 1.8.7 on Mac OS X Mountain Lion 10.8.4 在Mac OS X Mountain Lion 10.8.4上从Ruby 1.8.7升级到Ruby 2.0之后,Rails 3.2.13在开发模式下缓存我的助手模块,控制器和其他ruby代码。

The code changes are only picked up after I restart the server every time even in the rails console. 每次重新启动服务器后,即使在rails控制台中,代码更改也只会被拾取。 The reload! 重装! command in the console also does not work and does not reload my code changes until I restart the rails console again. 控制台中的command也不起作用,并且直到我再次重新启动Rails控制台之前,它不会重新加载我的代码更改。

The Javascript and Sass files are not cached but the Views, Controller and other ruby code is. 不缓存Javascript和Sass文件,而是缓存Views,Controller和其他ruby代码。 I checked the development.rb file and the following cache setting is set to false. 我检查了development.rb文件,并将以下缓存设置设置为false。

config.cache_classes = false

Also when starting the server it starts in development mode as seen on the console log 另外,启动服务器时,它将以开发模式启动,如控制台日志所示

Rails 3.2.13 application starting in development on http://0.0.0.0:3000

Not sure what happened but I did change the timezone and time of my system for testing purposes and reverted the time back to the actual time. 不知道发生了什么,但是出于测试目的,我确实更改了系统的时区和时间,并将时间恢复为实际时间。

I have even git cloned the repo again onto my system after restarting my machine with the correct time and timezone and still have the issue. 在正确的时间和时区重新启动机器后,我什至git再次将存储库克隆到我的系统上,仍然有问题。 Does anyone know how to fix this or how to force reload all the ruby code everytime the request is made in development mode? 有人知道如何解决此问题,或者每次在开发模式下提出请求时如何强制重新加载所有ruby代码吗?

If you also upgraded recently from an older Rails version. 如果您最近还从较旧的Rails版本升级。 If that is the case, note that lib is not autoloaded in Rails 3 . 如果是这种情况,请注意lib 不会在Rails 3中自动加载 You are talking about helper modules and controllers which should still be autoloaded, but lib won't be. 您正在谈论仍应自动加载的辅助程序模块和控制器,但lib不会。 You can change it to be autoloaded as noted in this answer , add another autoloaded dir, or move those classes until an existing autoloaded directory (eg app/models , if that is appropriate). 您可以按照此答案中的说明将其更改为自动加载,添加另一个自动加载的目录,或将这些类移动到现有的自动加载目录(例如, app/models ,如果合适)。

If you have stuff configured in config.autoload_once_paths then that could be a problem for reloading those, otherwise they should be reloaded per request per the guide (and you can look at the code here if you're curious about what is going on). 如果您在config.autoload_once_paths配置了某些内容,则可能会成为重新加载这些内容的问题,否则应根据指南的每个请求重新加载它们(如果您对正在发生的事情感到好奇,可以在此处查看代码)。

Also, check to make sure you are really running in development mode and note that you can't add lib to config.eager_load_paths in development.rb per this answer . 另外,请检查以确保您确实在开发模式下运行,并注意您不能根据此答案将lib添加到development.rb中的config.eager_load_paths中。

If you had time issues with the code, also maybe when you recloned the repo, you are still getting the wrong dates on the files. 如果您的代码有时间问题,也可能是当您重新克隆存储库时,文件上的日期仍然错误。 Try doing: find /path/to/rails/app -exec touch {} \\; 尝试做: find /path/to/rails/app -exec touch {} \\; to update the file mod datetimes. 更新文件mod日期时间。 (Also as an aside, you might want to be sure that the datetimes in your DB in created_at/updated_at are ok. Hopefully that isn't a problem, because that could be a mess.) (顺便说一句,您可能还想确保DB中created_at / updated_at中的日期时间是可以的。希望这不是问题,因为那可能是一团糟。)

Finally, be sure that classes that are under the autoloaded directory correspond to the modules that they are in. For example Foo::BarsController could be in app\\controllers\\foo\\bars_controller.rb but not in app\\controllers\\bars_controller.rb if you want it to be able to be autoloaded and reloaded properly. 最后,确保自动加载目录下的类与它们所在的模块相对应。例如, Foo::BarsController可以位于app\\controllers\\foo\\bars_controller.rb但不能位于app\\controllers\\bars_controller.rb您希望它能够自动加载并正确重新加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM