当文件更改时,如何使 lib/中的代码自动重新加载? [英] How do I make the code in lib/ automatically reload when the file changes?

查看:36
本文介绍了当文件更改时,如何使 lib/中的代码自动重新加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是对这个问题的跟进.在开发过程中,每次更改 lib/中的代码时,我都必须重新启动 rails 应用程序,以使代码更改生效.如何让此代码像控制器、模型等一样自动重新加载?

This is a follow up to this question. During development I have to restart the rails app everytime I change the code in lib/ in order for the code changes to take effect. How do I get this code to automatically reload like controllers, models, etc?

推荐答案

对于Rails 3,将文章中给出的说明与@science 的答案不同.在您的 environments/development.rb 文件中,添加以下行:

For Rails 3, vary the instructions given in the article from @science's answer. In your environments/development.rb file, add the lines:

ActiveSupport::Dependencies.autoload_paths << File::join( Rails.root, 'lib')
ActiveSupport::Dependencies.explicitly_unloadable_constants << 'MyModuleInLibFolder'

当然,用您的模块名称替换 MyModuleInLibFolder.

Of course, substitute the name of your module for MyModuleInLibFolder.

这篇关于当文件更改时,如何使 lib/中的代码自动重新加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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