# Help building plugin that requires overriting ruby controller methods

**URL:** https://meta.discourse.org/t/help-building-plugin-that-requires-overriting-ruby-controller-methods/259129
**Category:** Development
**Created:** [March 23, 2023, 9:52am UTC](https://meta.discourse.org/t/help-building-plugin-that-requires-overriting-ruby-controller-methods/259129 "2023-03-23T09:52:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Pabs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pabs/32/299271_2.png) [@Pabs](https://meta.discourse.org/u/Pabs)
#### Post date: [March 23, 2023, 9:52am UTC](https://meta.discourse.org/t/help-building-plugin-that-requires-overriting-ruby-controller-methods/259129/1 "2023-03-23T09:52:37Z")

</div>

Hi there,  
I’m trying to create a plugin that surfaces a checkbox when creating a topic on the UI, and that basically saves a new attribute in the topics table. Basically I need to get the attribute saved whehter the checbox was clicked or not, and then surface the new attrbute when visiting a Topics page.  
I started from the backend, adding a migration that creates a new boolean attribute to Topics, defaulted to false and next I was working on the controller. But I haven’t been able to find a way to add the new attribute in the function posts from TopicsController.  
I couldnt find anything like this on the tutorials.  
Thanks in advance!

```plaintext
after_initialize do

  module ::DiscourseXPlugin
    class ::TopicsController

      def posts
        Rails.logger.info '┌────────────┐'
        Rails.logger.info '│ Here we go │'
        Rails.logger.info '└────────────┘'  
      end
    end
  end
end

```

---

<div class="post-metadata">

### Author: ![Pabs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pabs/32/299271_2.png) [@Pabs](https://meta.discourse.org/u/Pabs)
#### Post date: [March 23, 2023, 10:39am UTC](https://meta.discourse.org/t/help-building-plugin-that-requires-overriting-ruby-controller-methods/259129/2 "2023-03-23T10:39:16Z")

</div>

An alternative to this, would be to create a new method in the controller, like “posts\_with\_new\_attribute” that is triggered through a new endpoint if the checkbox is clicked, but not sure if that would be more complicated.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [March 23, 2023, 4:44pm UTC](https://meta.discourse.org/t/help-building-plugin-that-requires-overriting-ruby-controller-methods/259129/3 "2023-03-23T16:44:45Z")

</div>

> [@Pabs](#):
>
> that surfaces a checkbox when creating a topic on the UI,

You’ll need to do that with a plugin outlet in the ember front end.

> [@Pabs](#):
>
> that basically saves a new attribute in the topics table

You want to use a TopicCustomField, not change any tables.

> [@Pabs](#):
>
> and then surface the new attrbute when visiting a Topics page.

You’ll want to add the custom field to the topic serializer.

You can look at other plugins that do those things for some examples.

---

<div class="post-metadata">

### Author: ![Pabs](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pabs/32/299271_2.png) [@Pabs](https://meta.discourse.org/u/Pabs)
#### Post date: [March 27, 2023, 12:06pm UTC](https://meta.discourse.org/t/help-building-plugin-that-requires-overriting-ruby-controller-methods/259129/4 "2023-03-27T12:06:32Z")

</div>

That worked! thanks!!
