Rails initializer 的載入順序

Rails initializer 的載入順序控制方法:initializer 依照檔名的字母順序載入,在檔名前加上數字前綴即可確保特定順序執行。

如果 rails app 裡的 initializer 有載入順序的需求的話

可以照著 Ruby On Rails Guide 這篇來設定

If you have any ordering dependency in your initializers, you can control the load order through naming. Initializer files are loaded in alphabetical order by their path. For example, 01_critical.rb will be loaded before 02_normal.rb.

檔名加個數字前綴,rails 就會以數字順序來依序載入~

comments powered by Disqus
Powered by Hugo. Theme Stack. All Rights Reserved.