Overriding a Method in a controller

Hi All,

I am attempting in overriding the behaviour of a an action controller, to be precise, the TopicsController#latest, I want to add a custom field to it as part of the response.

And in order to do that I have created a plugin, with:

after_initialize do
  class TopicsController 
    def latest
      render json: MultiJson.dump( "test": "ashdjagds" ); 

But it does not work when I make a request, I mean it does not return the {“test”: “ashdjagds” } part,

Any suggestion ?

You should check the class first. We don’t have latest method in TopicsController. Instead you need to override the ListController.