I want to make a after_update callback only execute when a certain configuration parameter is true.
At first I had something like this:
after_update :do_something
...
def do_something
return unless MyApp::Application.config.some_config
actualy_do_something
end
But then I thought, why not make the callback assignment conditional?
Like this:
after_update :do_something if MyApp::Application.config.some_config
However I don’t fully understand what Im doing here. When would this change? Only on server restarts? How do I test this behavior ? I can’t just set the config, the model file won’t be read again.
Please advise.
The standard way of achieving a conditional callback is to pass a symbol or proc to
:if:This format could also reference a global configuration setting on
Rails.configurationThis would allow the behavior of the application to change without having to restart the server or remove a constant and reload the file.