1
我想讓after_update回調只在特定配置參數爲true時執行。 起初,我有這樣的事情:以配置參數爲條件進行ActiveRecord回調並對其進行測試
after_update :do_something
...
def do_something
return unless MyApp::Application.config.some_config
actualy_do_something
end
但轉念一想,爲什麼不把回調分配條件? 這樣的:
after_update :do_something if MyApp::Application.config.some_config
但是,我不完全明白我在這裏做什麼。這個改變何時會發生?只有在服務器重新啓動?我如何測試這種行爲?我不能只是設置配置,模型文件將不會再被讀取。
請指教。