Rails 不刷新代码
在开发 Rails 应用程序时,我通常在处理代码时让开发服务器在本地运行(混合)。 代码中的更改会在快速刷新后生效。 除了我在文件夹中的 Lib 中编写的类之外,更改尚未生效。 这是否是一个已知问题? 可能是什么原因造成的? 在解决一个问题一段时间后,没有任何解决方案起作用,却发现这些解决方案都没有机会起作用,这是非常令人沮丧的。
谢谢你的帮助。
While developing a Rails app, I usually leave the dev server running locally (mongrel) as I work on the code. Changes in the code take affect after a quick refresh. EXCEPT changes havent been taking effect for a class I've been writing in the Lib in folder. Is this in any way a known problem? What could be causing this? It is very frustrating to work on a problem for a while, having no solutions work, only to find out none of those solutions even had a chance to work.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现 Rails 开发服务器(我使用 WEBrick)不会自动重新扫描某些文件夹以进行更改。 我确实知道供应商/插件文件夹,但我似乎记得在修改 lib 文件夹中的内容时遇到了麻烦。
基本上,每当我修改应用程序之外的内容时,我都会重新启动开发服务器。
I've found that there are some folders that the Rails dev server (I use WEBrick) doesn't automatically rescan for changes. The vendor/plugins folder is the one that I know of for certain, but I seem to recall having trouble modifying stuff in the lib folder.
Basically, anytime I modify something outside of app, I restart the dev server.
在 PHP 应用程序代码中,每次请求都会重新加载,这就是为什么您需要 APC 之类的东西来使其更快。 Rails 有不同的模型,应用程序启动一次就可以处理多个请求。
Rails 有一个特殊功能可以重新加载已更改的文件,但仅限于少数目录。 此外,它不会处理启动期间调用的代码中的更改(例如environment.rb或插件)。 在这种情况下,您必须重新启动服务器。
通过以下配置选项,在开发环境中默认启用类重新加载功能
In PHP application code is reloaded on every request, this is why you need something like APC to make it fast. Rails has a different model, the application is booted once and can handle multiple requests.
There is a special feature in Rails to reload files that have changed, but it is restricted only to a few directories. Moreover it won't handle changes in code that is invoked during startup (like environment.rb or plugins). In this case you have to restart the server.
The class reload feature is enabled by default in the development environment by the following configuration option