Skip to content

How is This Different?

tpitale edited this page Feb 5, 2013 · 2 revisions

@mremolt asked:

"From a concept perspective: What is the difference to the draper gem (https://github.com/drapergem/draper)? You seem to implement something that's already there or am I getting the project wrong?"

My answer:

"The draper gem is a decorator. It gives you the opportunity to add functionality to an existing model for presentational concerns. This is a fine solution!

The use of a distinct view class is only conceptually different. The methods are presentational and I feel they should be more closely aligned with the view and template, regardless of the model being used.

Practically speaking, you could use draper or presenters, or even just use helpers. I like the opportunity to use views to put my methods that are concerned with presentation, near to the presentation.

Feel free to reopen this if my answer is incomplete. I'm going to add this to the wiki, and hopefully improve/clarify it!"

I wish I had a whiteboard to draw on!

So, there are lots of different ways to help us follow some good OO practices. Small classes, with single responsibilities, for example. Decorators, are one way to achieve this. They're a very good way in fact. And, the draper gem is probably the best decorator for Rails.

I felt there might be another way, as well. No better, and not even all that different. I wanted to take the templates that Rails already has and reveal the hidden views (ActionView::Base) that exists underneath.

If we gave these views a nice name, and a conventional place to live in our Rails applications, this might be a nice, simple approach to keep presentational methods out of our models as well as keeping logic out of our ERB templates.

Clone this wiki locally