我有一個像這樣的rails設置。Rails加載類更改,而無需重新啓動服務器
應用程序/服務/ TestService.rb
class TestService
def self.doSomething
return 'Hello World!'
end
end
我使用控制器上的這個文件。
require 'TestService'
class IndexController < ApplicationController
def index
@message = TestService.doSomething
end
end
我還在config文件夾中的application.rb中添加了這個,這樣rails自動載入服務文件夾中的類。
config.autoload_paths += %W(#{config.root}/app/service)
但是,該應用程序似乎沒有拿起TestService類的更新。我該如何解決這個問題,以便在不重啓服務器的情況下顯示TestService類中的更改。
添加require_dependency ...似乎工作。但是,如果我刪除它,則不會加載對TestService的更改。 – 3coins
撤銷對「autoload_paths」配置的更改。根本不要設置該配置。 – yfeldblum
我已經刪除了。如果我在控制器中沒有require或require_dependency,則獲取此錯誤。未初始化的常量IndexController :: TestService – 3coins