2

I have a situation where some initialization code in my RoR application needs access to Rails url helpers, which means it needs to run after the application's routes have been loaded.

Based on guidance here, I have a working solution that involves the following:

Rails.application.config.after_initialize do
  Rails.application.reload_routes!
  #... initialization code here
end

The only problem with this is that it causes the routes to be loaded twice, once in the code above and a second time as part of the regular startup process. I was hoping that there would be some way to hook in to the initialization process in such a way that my initialization code would run after the regular route loading process. But I haven't found anything that does that. Any suggestions?

  • Sorry, a bit of experimentation revealed that I had a comically flawed understanding of the sequence of things during initialisation, and I've marked to delete my original answer. – rmlockerd Sep 01 '20 at 08:35

0 Answers0