Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am working on a large(ERP level) Rails project. We have 150 tables and more than 150 models. It takes minutes to find a model. Should we add all models under the models folder or should we put them in different subfolders? Same thing goes for controllers and views.

share|improve this question

2 Answers 2

I think you are running into the limitations of a single Rails application. Much like having too much code in one module, it sounds like you have too many modules in one application.

You should consider breaking it up into multiple applications using a service model, or you might also go the route of plugins or even better look at the new Engine framework.

This will benefit you multiple ways. It will force you to exercise good encapsulation and have good testable interface points between pieces.

Good Luck

share|improve this answer
    
You have described the situation very well. Thanks for that. Can you be more specific about multiple applications? How do I do that? Can you provide some links? –  Metin Jan 12 '11 at 4:22
    
I think he is implying that some of your functionality can be broken off into other projects as a sort of web service style architecture. That would allow some functional encapsulation and you would have smaller chunks to digest at a given time. –  Rig Mar 5 '12 at 0:44

I don't think it is necessary.
Doing the namespace route you mention (for models under separate directories) is what i would do.

I would also analyze the current performance issue further. Just having 150 models/tables should not cause more than a fraction of a second to be able to find and use the model! Is it actually the db query itself that takes a long time (when not cached)? That can be addressed in many ways (splitting data, aggregating data, adding indexes, changing queries to be more performant, etc.

You may or may not need to do controllers and views under separate directories.

To access things arranged this way you just use ::, e.g. if you put lots of models about bedrooms and attics and basements, etc. under a subdirectory 'buildings' and then want to access it in the controller, use ::, e.g. attics = Buildings::Attic.all

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.