自动重新加载 rails 模块 [英] Automatically reload rails module

查看:68
本文介绍了自动重新加载 rails 模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个包含在我的 rails 应用程序中的 ruby​​ 模块.我希望它在更改时自动重新加载.我已经进行了大量的谷歌搜索,并查看了此处讨论它的各种问题,但它们似乎都已过时或错误.

I'm developing a ruby module that I include in my rails app. I want it to be reloaded automatically when it changes. I've done extensive googling, and looked at the various questions here that discuss it, but they all seem out of date or wrong.

当外部模块发生变化时,如何让其重新加载到 rails 中?我曾尝试将其名称添加到 ActiveSupport::Dependencies.unloadable_constants,但在我在控制台中键入 reload! 后,如果没有 NameError: uninitialized constant foo,即使我做了另一个require 'foo_module'.有谁知道如何让这个工作?

How do I get an external module to be reloaded in rails when it changes? I've tried adding its name to ActiveSupport::Dependencies.unloadable_constants, but after I type reload! in the console, I can no longer refer to that symbol without a NameError: uninitialized constant foo, even if I do another require 'foo_module'. Does anyone know how to get this working?

注意:这里是一个可能的重复,但请注意对答案"的评论说它从未解决模块的问题.还有 这个问题 在答案中有一个死链接,最后 这个,这也解决不了.

Note: here is one possible dup, but note in the comments to the 'answer' that it never solved the problem for modules. There's also this question which has a dead link in the answer, and finally this one, which also doesn't solve it.

推荐答案

我找到了方法:

  1. 确保 FooModulelib/foo_module.rb 中.
  2. 使用 require_dependencylib/foo_module.rb 中要求你的外部库.
  1. Make sure FooModule is in lib/foo_module.rb.
  2. Use require_dependency to require your external library in lib/foo_module.rb.

这两个步骤都是必需的,不需要其他步骤.

These steps are both required, and no others are required.

这篇关于自动重新加载 rails 模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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