I'm trying to decorate a controller from another rails engine. I have one controller method that I want to extend with just one more line. I rather not duplicate the whole original controller method.
This is what I tried:
Backend::BaseContentsController.class_eval do
def booking_update
# do some stuff
update
end
alias_method :update, :booking_update
end
Unfortunately this throws the exception stack level too deep
. Normally with inheritance I could just call super. What would be ideal to do in my case?
You should try alias_method_chain
:
def update_with_booking
# do some stuff
update_without_booking # that's your old update
end
alias_method_chain :update, :booking
module Decorator
def update
# do some stuff
super
end
end
Backend::BaseContentsController.prepend(Decorator)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With