-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The gem breaks usage of Rails URL helpers when used outside views and controllers #9
Comments
We ran in the same thing. One workaround I'm trying now is: # config/initializer/console.rb
Rails.application.console do
Rails.application.routes.url_helpers.instance_eval do
def method_missing(m, *args, &block)
if m.to_s.end_with?('_path', '_url')
RoutesLazyRoutes.eager_load!
return public_send(m, *args, &block)
end
super
end
def respond_to_missing?(m, include_private = false)
m.to_s.end_with?('_path', '_url') || super
end
end
end I've confirmed helpers in |
To revisit my earlier comment... that workaround didn't work. Partially, it's because the Rails URL helpers aren't normally available in the console from the top level object. The underlying problem I was trying to fix was ActionMailers failing when they used URL helpers. It came up for someone today, and I had a realization for a fix. In your `config/console Rails.application.console do
# Make sure that routes are available to Mailers when running from a console
if defined?(RoutesLazyRoutes)
ActiveSupport.on_load(:action_mailer) do
before_action { RoutesLazyRoutes.eager_load! }
end
end It seems this should be feasible in the railtie, so I can try a patch for this. |
For those using sidekiq, you can update your # config/initializers/sidekiq.rb
Sidekiq.configure_server do |config|
if defined?(RoutesLazyRoutes)
Rails.application.config.after_initialize do
RoutesLazyRoutes.eager_load!
end
end |
Issue is mentioned here discourse/discourse#14581.
I wanted to use this gem in our application after following this Twitter thread but found above issue so I couldn't use it. I hope that issue will get resolved soon.
The text was updated successfully, but these errors were encountered: