1

我已经尝试了大多数解决方案,例如require_dependency添加和启用文件夹,但仍然没有骰子。autoloadapplication.rblib

这是我的应用程序的设置方式:

我有lib/index_tank_searcher.rb

  class IndexTankSearcher < Spree::Core::Search::Base
    def method
    end
  end   

Spree::Config.searcher_class = IndexTankSearcherconfig/intializers/spree.rb.

关于如何确保index_tank_searcher.rb自动重新加载而不在每次更改时重新启动服务器的任何想法?

4

1 回答 1

2

重新加载类不会改变现有的类。要卸载的类从它们的常量中取消分配,并分配一个新副本。这在控制台中很容易验证

1.9.3p194 :002 > User.object_id
 => 70274894338560 
1.9.3p194 :003 > reload!
Reloading...
 => true 
1.9.3p194 :004 > User.object_id
 => 70274935456220 

但是Spree::Config.searcher_class仍然设置为原始IndexTankSearcher类。

您可以添加一个to_prepare回调,该回调将在开发中的每个请求上调用,但在生产中仅一次(在启动时)

于 2012-09-11T12:06:35.177 回答