المساعدة في بناء إضافة تتطلب تجاوز أساليب وحدة تحكم Ruby

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!

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
إعجاب واحد (1)

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.

إعجاب واحد (1)

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

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

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.

إعجاب واحد (1)

That worked! thanks!!