Skinny models

As  rails developers we try to maintain dry princples along with that we also focus in skinny controllers and skinny models.

One of the way I have used to approach skinny model would be by using concerns with.I had a model called person.rb which was very length.There were alot of relations and validations and authenticating method present in it.Once my app was up and working well I tried to refractor my code.

I have created a config file called  concerns.rb in config/initializers so that these gets preloaded.


class << ActiveRecord::Base

def concerned_with(*concerns)

concerns.each do |concern|

require_dependency “#{name.underscore}/#{concern}”



Once this is done I have created a folder which says person and created files for authentication methods,validations,association.In the person.rb model I have included them as concerned_with :validations, :associations, :authenticated_methods

By using the above method I got a skinny model with the general rails standards.


, ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: