There’s been lots of discussion lately about making Rails more object oriented. I’m not sure what spurred all the recent discussions, but I think it’s great that there are lots of discussions spreading around the community.
When I first began learning Rails I quickly bumped into those articles talking about fat models and skinny controllers. I quickly followed suite as it seemed to make sense; initially. Then I got to a point where thought, “why not put some of this stuff into plain old ruby objects in the lib directory?”. I began doing that and have continued doing that ever since and I, as many recent Rails developers have written and talked about, think you should too.
Some of the recent libraries, posts or books related to more object oriented Rails include:
Prior to all of those, and I’m sure I’m missing some, I heard Jeff Casmir’s talk at RailsConf 2011. He talked about potentially getting away from the dogma of fat models, skinny controllers by suggesting people create more libraries/gems, use the presenter pattern, etc.
In parting I’d just like to say, don’t be afraid of having code outside of app/models and app/controllers. Ruby is object oriented and Rails is a framework that is built with Ruby, so go ahead and use your bad ass OO skills already! Rails provides lots of conventions and opinionated views, but that doesn’t mean you can’t do what makes the most sense for your applications. And please, feel free to use the lib directory or even create some gems that you could potentially reuse. Hell, get real crazy and build some engines! (I’ve built 3 in the last 2 months).