4

The following code used to work in Rails 6.0.4.8 but no longer works in 6.1.X (I tried all minor versions, even the latest 6.1.6 has this behaviour; the engine itself is legacy code, unfortunately, we can't remove it easily):

# config/routes.rb
Spree::Core::Engine.routes.named_routes.url_helpers_module.include(DynUrlHelper)

MyApp::Application.routes.draw do
  mount Spree::Core::Engine, at: "/"
end
# app/helpers/dyn_url_helper.rb
module DynUrlHelper
  def dyn_path(target)
    # ...
  end
end

It throws an undefined method error when I try to use #dyn_path in a controller or view:

undefined method `dyn_path' for #<MyController:0x00007facc9227298>

Upon investigating the issue, I noticed, that when I change a file and Zeitwerk reloads my code, it works! But a fresh started app fails. So I guess it has something to do with caching the named routes helpers?

The only thing I found is this question Rails route issue after upgrading to rails 6.1 linking to this Github issue https://github.com/rails/rails/issues/42218. But I'm not sure if it really is the same problem.

23tux
  • 14,104
  • 15
  • 88
  • 187

0 Answers0