# Override existing Discourse methods in plugins

**URL:** https://meta.discourse.org/t/override-existing-discourse-methods-in-plugins/83389
**Category:** Developers
**Tags:** plugin-guides, how-to
**Created:** [March 20, 2018, 11:37am UTC](https://meta.discourse.org/t/override-existing-discourse-methods-in-plugins/83389 "2018-03-20T11:37:16Z")
**Posts on this page:** 1
**Showing post:** 12

<div class="post-metadata">

### Author: ![TimFelix](https://avatars.discourse-cdn.com/v4/letter/t/919ad9/32.png) [@TimFelix](https://meta.discourse.org/u/TimFelix)
#### Post date: [November 15, 2025, 6:33pm UTC](https://meta.discourse.org/t/override-existing-discourse-methods-in-plugins/83389/12 "2025-11-15T18:33:20Z")

</div>

New to discourse and Rails development.I’m using the Dev Container environment (in VS Code) locally.The guides and docs have been helpful.

I was wondering if anyone has any tips on how to override core discourse classes, specifically getting it to persist in a local development environment.

In my plugin, I am trying to override a method in the core discourse `TopicEmbed` class. (using the general approach nicely documented by @angus above.) **It works once when I rebuild and reload VS Code, but on subsequent http requests my override is never invoked.**

My override is defined in `/plugins/my-plugin/app/models/override.rb` and I use `require_relative` to include this file in my `plugin.rb`.

```plaintext
#override.rb:
class ::TopicEmbed

  # a module that will be prepended into TopicEmbed.singleton_class
  module TopicEmbedOverrideModule
    # method in TopicEmbed
    def first_paragraph_from(html)
      Rails.logger.info(“my override is happening! ”)

      # continue with the original implementation provided by TopicEmbed.
      super

    end
  end

  # do the prepend here
  singleton_class.prepend TopicEmbedOverrideModule
end

```

I suspect this my persistence challenge may be due to my dev environment and how ruby code is compiled/cached.  
I also tried `rm -rf tmp; bin/ember-cli -u`and `bundle exec rake tmp:cache:clear`.

---

_[View the full topic](https://meta.discourse.org/t/override-existing-discourse-methods-in-plugins/83389)._
