Rails 3 loading all models on startup

后端 未结 3 1418
情书的邮戳
情书的邮戳 2021-02-05 18:32

I have a class method mixed in to all my models. the method gets called when the model class is evaluated. unfortunately (for me), this seems to be on-demand, whenever the model

3条回答
  •  清歌不尽
    2021-02-05 19:02

    I dont know if this is ideal, but it works for me. Somewhere in the config/initialize/, i do this:

    Dir.glob("#{Rails.root}/app/models/*.rb").sort.each { |file| require_dependency file }
    

    and that preloads my models

提交回复
热议问题