Create sub folders in your Rails application

I got some nice emails concerning my restful search and the Object-oriented approach to ActiveRecord posts.

But a few of those mails had another thing in common. Some users find all the finder classes in the helper folder overwhelming, and they don’t like having them in the same folder as their view helpers.

Well, the thing you can do, is put all the finder classes in a subfolder. Lets call the subfolder “finders”, just for the fun of it :p.

Now Rails won’t load those finders anymore, since it won’t recognise your newly created subfolder. So open your environment.rb file and paste in the following code:

Dir.glob("#{RAILS_ROOT}/app/helpers/*[^(.rb|.ignore)]").each{|dir| config.load_paths << dir }

This will tell Rails to load all files and folders in the helpers folder, that don’t contain .rb or .ignore in its name.

So all the view helpers won’t get loaded again, and if you have a subfolder that you don’t need to be loaded anymore in your helpers folder, but still want the code, you can just rename the folder.

So I hope this might help you guys keeping your application clean. Off course you can also use this on other subfolders you might want to create 😉