# Overriding a Method in a controller

**URL:** https://meta.discourse.org/t/overriding-a-method-in-a-controller/92657
**Category:** Development
**Created:** [July 18, 2018, 4:19pm UTC](https://meta.discourse.org/t/overriding-a-method-in-a-controller/92657 "2018-07-18T16:19:27Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Sanjay1](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@Sanjay1](https://meta.discourse.org/u/Sanjay1)
#### Post date: [July 18, 2018, 4:19pm UTC](https://meta.discourse.org/t/overriding-a-method-in-a-controller/92657/1 "2018-07-18T16:19:27Z")

</div>

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:

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

```

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

Any suggestion ?

---

<div class="post-metadata">

### Author: ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)
#### Post date: [July 19, 2018, 4:18pm UTC](https://meta.discourse.org/t/overriding-a-method-in-a-controller/92657/2 "2018-07-19T16:18:19Z")

</div>

You should check the class first. We don’t have `latest` method in `TopicsController`. Instead you need to override the [`ListController`](https://github.com/discourse/discourse/blob/18f50ca01abfa5497b3dc423470c3b5e84e48771/app/controllers/list_controller.rb#L58).
