Garbage Burrito!

An internet web blog by Ben Kittrell

Organizing Large Rails Projects, the Simple Way

Organizing Large Rails Projects, the Simple Way
Ben Kittrell - 12/07/2010 15:48:00
Comments: 3
One thing that Rails isn't particularly good at is organization of large projects.  There's one controllers directory, one models directory, etc.  As Doodlekit started to grow I tried to find ways to keep this in check.  

I've been using Engines for a couple of years and I've found it way to cumbersome for just organizing code.  I looked into Namespacing, but I don't want to have the namespaces in the URLs.  All I want is to be able to organize code into subdirectories.

Right now I just need one extra subdirectory for Addons. Here's what my directory structure looks like.

app
-- controllers
---- sites_controller.rb
---- ...
---- addons
------ forms_controller.rb
------ ...
-- models
---- site.rb
---- ...
---- addons
------ form.rb
------ ...
-- views
---- sites
---- ...
---- addons
------ forms
------ ....


Just like you would have with namespacing, but I'm not actually namespacing.  To get this to work you only need to add a few lines to your environment.rb file.

Rails::Initializer.run do |config|

    ....
    
    config.load_paths += %W(
      #{RAILS_ROOT}/app/controllers/addons
      #{RAILS_ROOT}/app/models/addons
      #{RAILS_ROOT}/app/helpers/addons
    )

    config.controller_paths += %W(
      #{RAILS_ROOT}/app/controllers/addons
    );

    .....
   
end

ActionController::Base.view_paths.insert(1, "app/views/addons")


 
Tags: rails, doodlekit
Comments: 3

Comments

1. Robert Williams  |  my website   |   06/06/2011 13:50:45

I actually found this useful I''m not a spammer,

Organising our Rails project now that it's grown in size is something we need and this has pointed me in the right direction

Thanks!

2. James Mickle   |   10/22/2011 08:00:47

I've been using Engines for a couple of years and I've found it way to cumbersome for just organizing code. <a href ="http://madrid.senorstag.com">madrid karting</a> I looked into Namespacing, but I don't want to have the namespaces in the URLs. All I want is to be able to organize code into subdirectories.

3. Christian Louboutin On Sale  |  my website   |   01/17/2012 10:08:06

Good article , your article rich in literary talent , technique and describe very unique style of humor , brings a joy and festivity. Not only that, your article is rich with a lot of useful knowledge and helpful information . Thank you for sharing .

Post a Comment


Please enter the word below.


powered by Doodlekit™ Free Website Builder by Doodlebit™ Website Company