Elegant way to structure models into subfolders without creating submodules

前端 未结 10 557
一整个雨季
一整个雨季 2020-12-04 08:24

I have numerous models in my app/models folder. I\'d like to clean this folder up a little bit. Move models that belong to each other in subfolders. The problem is that by c

10条回答
  •  无人及你
    2020-12-04 09:11

    We needed to do this, and there is a very simple way.

    move your models into the sub-folders, and then tell rails to load files from all subfolders in your environment.rb file:

    config.load_paths += Dir["#{RAILS_ROOT}/app/models/*"].find_all { |f| File.stat(f).directory? }
    

    No namespacing required, and the models can be referred to as normal in your app

提交回复
热议问题