RAILS_ROOT/app Organization

As an app grows, so does the amount of files in app/models. Here is a simple tip to help reduce the clutter: move mailers, observers, and sweepers out of app/models into app/mailers, app/observers, and app/sweepers, respectively. For rails to still load them, you will need to modify config/environment.rb:

# clean up app/models a bit
%w{mailers observers sweepers}.each do |dir|
    config.load_paths << "#{RAILS_ROOT}/app/#{dir}"
end

As a bonus, you can now automatically record your observers with ActiveRecord instead of having to add them individually in environment.rb:

config.active_record.observers = Dir.glob("#{RAILS_ROOT}/app/observers/*.rb").collect do |filename|
    filename.split('/').last.split('.').first.to_sym
end
One issue with this reorganization is that the generators will continue to create mailers, observers, and sweepers in app/models. For me, that is not a big deal – I don’t create them often, and manually move them after generation. I suspect it would be trivial to adjust the generators to use the new path, but have not looked in to it.