Rails initializer that runs *after* routes are loaded?

前端 未结 2 473
悲哀的现实
悲哀的现实 2020-12-20 11:40

I want to set a class attribute when my Rails app starts up. It requires inspecting some routes, so the routes need to be loaded before my custom code runs. I am having trou

2条回答
  •  伪装坚强ぢ
    2020-12-20 11:54

    If you're trying to run code in an initializer after the routes have loaded, you can try using the after: option:

    initializer "name_of_initializer", after: :add_routing_paths do |app|
      # do custom logic here
    end
    

    You can find initialization events here: http://guides.rubyonrails.org/configuring.html#initialization-events

提交回复
热议问题