# In a view, call a helper method from another controller

**URL:** <https://www.ruby-forum.com/t/in-a-view-call-a-helper-method-from-another-controller/170216>\
**Category:** Rails\
**Created:** [June 14, 2009, 6:31am UTC](https://www.ruby-forum.com/t/in-a-view-call-a-helper-method-from-another-controller/170216 "2009-06-14T06:31:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [June 14, 2009, 6:31am UTC](https://www.ruby-forum.com/t/in-a-view-call-a-helper-method-from-another-controller/170216/1 "2009-06-14T06:31:36Z")

</div>

I need to call a helper method from another controller. The catch is  
that I have the same method name defined in my current controllers  
helper.

Here the partial will use the the default column\_list defined in my  
helper.  
\<%=render ‘companies/company’, :object =\> @company%\>  
For example, if I change the call to specify the method, it still runs  
great:  
\<%=render ‘companies/company’, :object =\> @company, :locals =\>  
{:column\_list =\> method(:column\_list)}%\>

Here I want to use another’s helper column\_list:  
\<%=render ‘companies/companies’, :object =\>  
@customers\_employees, :locals =\> {:column\_list =\>  
CustomersEmployeesController.new.method(:column\_list)} %\>

I get this error:  
undefined method `column_list' for class`CustomersEmployeesController’

How can I pass the reference to the right helper method?

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [June 19, 2009, 11:29pm UTC](https://www.ruby-forum.com/t/in-a-view-call-a-helper-method-from-another-controller/170216/2 "2009-06-19T23:29:42Z")

</div>

On 14 juin, 05:18, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > undefined method `column_list' for class `CustomersEmployeesController’
> 
> > How can I pass the reference to the right helper method?
> 
> helper\_methods are not methods of the controller - they are methods of  
> the associated helper module (usually CustomerEmployeesHelper in this  
> case). Does that help ?

I realize that.  
I want to call a helper method column\_list available when running  
CustomersEmployeesController. CustomersEmployeesController inherits  
from CompaniesController, which includes the helper method needed. I  
cannot hardcode the file name of the module where this method is,  
because I might redefine it later in CustomersEmployeesHelper and that  
would drive crazy the maintenance programmer when will find that  
normal mechanisms of inheritance don’t work.

I thought that instantiating CustomersEmployeesController will include  
automatically his Helper module, but it appears it doesn’t.

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [June 14, 2009, 12:19pm UTC](https://www.ruby-forum.com/t/in-a-view-call-a-helper-method-from-another-controller/170216/3 "2009-06-14T12:19:39Z")

</div>

On Jun 14, 5:31 am, Constantin G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How can I pass the reference to the right helper method?  
> helper\_methods are not methods of the controller - they are methods of  
> the associated helper module (usually CustomerEmployeesHelper in this  
> case). Does that help ?

Fred

---

<div class="post-metadata">

**Author:** ![costi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@costi](https://www.ruby-forum.com/u/costi)\
**Post date:** [June 19, 2009, 11:58pm UTC](https://www.ruby-forum.com/t/in-a-view-call-a-helper-method-from-another-controller/170216/4 "2009-06-19T23:58:28Z")

</div>

On Jun 19, 10:28 pm, Constantin G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I want to call a helper method column\_list available when running  
> CustomersEmployeesController. CustomersEmployeesController inherits  
> from CompaniesController, which includes the helper method needed. I  
> cannot hardcode the file name of the module where this method is,  
> because I might redefine it later in CustomersEmployeesHelper and that  
> would drive crazy the maintenance programmer when will find that  
> normal mechanisms of inheritance don’t work.
> 
> I thought that instantiating CustomersEmployeesController will include  
> automatically his Helper module, but it appears it doesn’t.

Why not put the relevant helper methods in a module that both  
controllers use ?

Fred
