# DRYing up between Helper and Controller

**URL:** <https://www.ruby-forum.com/t/drying-up-between-helper-and-controller/110659>\
**Category:** Rails\
**Created:** [July 29, 2007, 2:40am UTC](https://www.ruby-forum.com/t/drying-up-between-helper-and-controller/110659 "2007-07-29T02:40:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [July 29, 2007, 2:40am UTC](https://www.ruby-forum.com/t/drying-up-between-helper-and-controller/110659/1 "2007-07-29T02:40:28Z")

</div>

I have a few small methods as part of my authorisation scheme, These  
mostly get used by controllers, but sometimes I want a template to  
call them too.

For example, there are methods called is\_editor?, is\_author? and  
is\_publisher? currently in application.rb.

I am including/excluding elements for navigation in the user interface  
based upon these roles. Therefore I want one definition of these  
methods that “everyone” can use.

Whats the right rails way to achieve this?

Cheers, --Kip

---

<div class="post-metadata">

**Author:** ![Kip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/8e7dd6/32.png) [@Kip](https://www.ruby-forum.com/u/Kip)\
**Post date:** [July 29, 2007, 1:34pm UTC](https://www.ruby-forum.com/t/drying-up-between-helper-and-controller/110659/2 "2007-07-29T13:34:57Z")

</div>

Kip wrote:

> I have a few small methods as part of my authorisation scheme, These  
> mostly get used by controllers, but sometimes I want a template to  
> call them too.
> 
> For example, there are methods called is\_editor?, is\_author? and  
> is\_publisher? currently in application.rb.
> 
> I am including/excluding elements for navigation in the user interface  
> based upon these roles. Therefore I want one definition of these  
> methods that “everyone” can use.
> 
> Whats the right rails way to achieve this?

I’d issue “helper\_method :is\_editor?” in my application controller.  
Others prefer a construction like so:

class ApplicationHelper  
def for\_editors  
yield if is\_editor?  
end  
end

Now you can do:

\<% for\_editors do -%\>  
Editors only!  
\<% end -%\>

Whichever is prettier is a matter of preference I suppose.

–  
Roderick van Domburg

> **[De domeinnaam Nedforce.nl is te koop.](http://www.nedforce.nl)**
>
> Deze mooie domeinnaam kan al over een paar minuten van jou zijn. Betalen gaat eenvoudig en vertrouwd via iDEAL. Direct na de betaling ontvang je de verhuiscode per e-mail en kun je aan de slag.
