How to monkey-patch code that gets auto-loaded in Rails?

前端 未结 6 1472
悲&欢浪女
悲&欢浪女 2020-12-14 18:39

I\'m monkey-patching a Rails engine with something like:

SomeClass.class_eval do
  # ...
end

The first time I hit the web site, on developm

6条回答
  •  醉酒成梦
    2020-12-14 19:09

    Unfortunately, there is no way to hook into the reloading mechanism of Rails 2.x. What you could do, is place your patch somewhere in the app or lib directory. (lib/core_ext is probably the preferred location). Then add the directory to the autoload_paths in your config.

    You might also need to open the class, rather than using class_eval.

提交回复
热议问题