# Need a thumbs up or a thumbs down

**URL:** <https://www.ruby-forum.com/t/need-a-thumbs-up-or-a-thumbs-down/124736>\
**Category:** Rails\
**Created:** [January 2, 2008, 12:30am UTC](https://www.ruby-forum.com/t/need-a-thumbs-up-or-a-thumbs-down/124736 "2008-01-02T00:30:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [January 2, 2008, 12:30am UTC](https://www.ruby-forum.com/t/need-a-thumbs-up-or-a-thumbs-down/124736/1 "2008-01-02T00:30:23Z")

</div>

I have a very simple idea, and need a simple “yes thats a good idea” or  
“no, thats a bad idea, heres why”. I want to create a disp helper method  
to display ActiveRecord objects. Quick example:

\<%= disp(@user, :type =\> :multi\_line\_html) %\>

This would produce:

**\<%= link\_to “benj0323”, user\_profile\_url(:id =\> user.id)  
%\>**  
  
Ben J.  
  
Registered on: Jan 1, 2008

or I could do:

\<%= disp(@user, :type =\> :single\_line\_text) %\>

This would produce:

benj0323 - Ben J. - Registered on: Jan 1, 2008

All that I want is a helper method to display the state / information  
about an object. I simply specify a type depending on how I want the  
data formatted. This is nice because I can instantly change how users  
are displayed throughout the software if I need. A good example is if we  
add privacy featured to the application, and a user can specify that  
they do NOT want their name show. So I would go to that one file and add  
in the conditional check to display their name or not, not this feature  
is effective throughout the whole software.

What do you think? Good idea or bad idea? Or is there a better way to  
conquer the situation I described above?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [January 2, 2008, 1:00am UTC](https://www.ruby-forum.com/t/need-a-thumbs-up-or-a-thumbs-down/124736/2 "2008-01-02T01:00:55Z")

</div>

On Jan 1, 3:30 pm, Ben J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Ben J.  
>   
> All that I want is a helper method to display the state / information

It sounds like you just need two view helpers (or partials). I’m not a  
big fan of passing in a ‘type’ to a helper in this case. Mainly  
because you’ll need to have a conditional in the helper, which could  
just as well be two separate helpers. I’m not a big fan of using much  
html in helpers and usually delegate that to a partial.

Robby

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [January 2, 2008, 1:15am UTC](https://www.ruby-forum.com/t/need-a-thumbs-up-or-a-thumbs-down/124736/3 "2008-01-02T01:15:32Z")

</div>

On Wed, Jan 02, 2008 at 12:30:23AM +0100, Ben J. wrote:

> I have a very simple idea, and need a simple “yes thats a good idea” or  
> “no, thats a bad idea, heres why”. I want to create a disp helper method  
> to display ActiveRecord objects. Quick example:
> 
> \<%= disp(@user, :type =\> :multi\_line\_html) %\>  
> […]  
> or I could do:
> 
> \<%= disp(@user, :type =\> :single\_line\_text) %\>  
> […]  
> What do you think? Good idea or bad idea? Or is there a better way to  
> conquer the situation I described above?

It’s a common idea, but there are two better approaches. One is having a  
set of modules that parallel one’s models, much the way helpers parallel  
one’s controllers, that provide methods on the model so it knows how to  
render itself. I swear there is a plugin to handle this and  
automatically  
extend models before views run, but I can’t remember the name. (It also  
wouldn’t be that hard to write, though it could be a challenge to make  
it  
both dependable and efficient.)

The other, much simpler, approach is to have appropriate partials for  
each,  
e.g.:

\<%= render :partial =\> ‘/shared/user/multi\_line\_html’, :object =\> @user  
%\>

or

\<%= render :partial =\> ‘/shared/user/single\_line\_text’, :object =\> @user  
%\>

> Thanks for your help.  
> –Greg
