I have the snippet below in one of my AR models:
after_update :cache_bust
The cache_bust
method in the model accepts a parameter (boolean) that sets the value of itself to false
by default.
How can I pass true
to this method in the model from my ActiveRecord callback defined above it?
Ex: after_update :cache_bust(true)
does not work because it's a symbol, how can I pass true
to the method's param?
Short answer is No.You cannot pass any arguments. You could use attr_accessor to create a virtual attribute and set that attribute.
Try this?
Very easy to pass params from controller to callback, you can call name of params in model. Example:
In controller:
In model:
Based on your clarification, you can achieve what you're looking for by using optional method parameters, like so:
In the scenario where the method is called from the
after_update
callback, the parameter is not passed, but defaults to true. Otherwise, if the method is called from anywhere else "manually", you have the option of passing whatever value you wish to that method.