Url_helpers has an `example.org` prefix when broadcasting inside an after_create_commit

Good day people, hoping you’re having a great day.

So, i have a model that has a simple after_create_commit that broadcasts the object to the DOM via Streams.

The partial, references a url to pass it as a data- attribute for the Stimulus controller. I noticed, when the new partial is rendered to the DOM, it has an exmple.org set as it’s host. Here is how it looks like

I tried setting the host in the Rails default_url_options. But, that does not seem to work. However, if render the url as in Rails.application.routes.url_helpers.THE_URL. All works fine, is there anyway to fix this?

Thank you for reading this!

Specifying the host inside the environments, like so

  config.action_controller.default_url_options = {host: "localhost", port: "3000"}

Did the trick for me

I figured this out thanks to Default renderer not used when rendering outside of controllers · Issue #31979 · rails/rails · GitHub