(Rails)重新加载"lib"文件.文件而不必重新启动服务器...? [英] (Rails) Reloading "lib" files without having to restart server...?

查看:145
本文介绍了(Rails)重新加载"lib"文件.文件而不必重新启动服务器...?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails中是否有任何方法可以让ENV重新加载"lib"?文件而不必重新启动服务器?我正在使用"lib"模块中的某些类.但是,为了查看我的更改,我必须每次都重新启动服务器.我猜想这就是Rails的工作方式,但是在开发库文件和/或插件时,这很繁琐.

Is there any way in Rails to have the ENV reload "lib" files without having to restart the server? I'm working with some classes that I have inside a module in "lib". However, in order to see my changes I must restart the server each time. I'm guessing this is the way Rails is intended to work, but it is quite tedious when developing library files and/or plugins.

我肯定是要解决这个问题....?

Surely I'm going about this wrong....?

最佳

答案1和2都不适合我.取而代之的是,我从使用模块的控制器中看到了错误.仅供参考,我在"lib/xmlitems"目录中有3个文件目录.我尝试加载该子目录,然后引用了"requires"单个文件.所有其他文件.我可以单独加载所有文件吗?

Neither answer 1 nor 2 worked for me. Instead I was presented with errors from the controllers that made use of the Module. FYI, I have 3 files in my "lib/xmlitems" directory. I attempted to load that subdirectory then I referenced the single file that "requires" all other files. Am I to individually load all files?

推荐答案

对于 Rails 3 Rails 4.0 ,请更改@txwikinger答案中给出的说明.在您的environment/development.rb文件中,添加以下行:

For Rails 3 and Rails 4.0, vary the instructions given in @txwikinger'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 << '<my modules in lib>'

这篇关于(Rails)重新加载"lib"文件.文件而不必重新启动服务器...?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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