Perhaps I am just not using the correct terminology for Ruby (and if I am please correct me), but Google just isn't helping me on this one.
What I have is a class (call it OrderController) that extends another class (call it BaseStoreController). In the BaseStoreController I have defined a before_filter
that is used throughout my site, with the small except of my OrderController. In this very particular situation I needed to define a custom before_filter
that needs to do some additional logic and then call the before_filter
defined in my BaseStoreController.
What I do not know is how to do this.
Here is what I've tried, but it appears that the 'super' keyword isn't what I was expecting it to be:
class BaseStoreController < ActionController::Base before_filter :authorize protected def authorize #common authroization logic here end end
and
class OrderController < BaseStoreController before_filter :authorize protected def authorize #additional authroization logic here super.authorize end end
The end result of my code is that the authorize method in the OrderController is failing with the following error:
You have a nil object when you didn't expect it! The error occurred while evaluating nil.authorize
Usually, method overloading happens inside a single class, but a method can also be treated as overloaded in the subclass of that class — because the subclass inherits one version of the method from the parent class and then can have another overloaded version in its class definition.
Using a qualified-id to call a base class' function works irrespectively of what happens to that function in the derived class - it can be hidden, it can be overridden, it can be made private (by using a using-declaration), you're directly accessing the base class' function when using a qualified-id.
Yes it is overloading , This overloading is happening in case of the class ' C ' which is extending P and hence having two methods with the same nam e but different parameters leading to overloading of method hello() in Class C .
Have you tried calling the base class's "authorize
" method with just "super
" instead of "super.authorize
"?
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