Noah Noah - 1 year ago 108
Ruby Question

Rails pass params/arguments to ActiveRecord callback function

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?

Answer Source

There are four types of callbacks accepted by the callback macros: Method references (symbol), callback objects, inline methods (using a proc), and inline eval methods (using a string).

Try this?

after_update -> { cache_bust(true) }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download