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?