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`.
#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 -uand bundle exec rake tmp:cache:clear.