jpablobr.com

→ tip on refactoring mvc models

More on: tip, refactoring, mvc, models, Mon Jul 26 20:02:26 +0000 2010

Say you follow the "Fat Models, skinny controllers" well known convention. A nice approach for way too FAT models, is to separate their logic into separate directories such as the following structure:

Then you can do something like this to extend your user.rb model (thanks to Ruby class opening )

For this to work you will only have to add this line in your environment.rb

config.load_paths += %W( #{RAILS_ROOT}/app/models/role #{RAILS_ROOT}/app/models/user etc...)

Now based on your directory tree, you have a cool new level of semantics on your app.

more on namespaced models
blog comments powered by Disqus