# How to include a helper method in a controller

**URL:** <https://www.ruby-forum.com/t/how-to-include-a-helper-method-in-a-controller/166199>\
**Category:** Rails\
**Created:** [April 22, 2009, 6:04pm UTC](https://www.ruby-forum.com/t/how-to-include-a-helper-method-in-a-controller/166199 "2009-04-22T18:04:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [April 22, 2009, 6:04pm UTC](https://www.ruby-forum.com/t/how-to-include-a-helper-method-in-a-controller/166199/1 "2009-04-22T18:04:39Z")

</div>

Hi there,

why do I get the error…

undefined method `format\_phone\_number\_for’ for  
#User::MailingsController:0xb70aae58

… in this situation:

# controllers/user/mailings\_controller.rb:

class User::MailingsController \< ApplicationController  
def whatever  
[…]  
[…] format\_phone\_number\_for(@somebody) # \<- why is this  
“undefined” ?  
[…]  
end  
end

# helpers/phonenumber\_helper.rb:

module PhonenumberHelper  
def format\_phone\_number\_for(parent)  
[…]  
end  
end

And what do I have to do to have this method available in this  
controller?  
(I have already tried by including “helper PhonenumberHelper” in the  
controller)

Thanks for your help!  
Tom

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [April 23, 2009, 7:55am UTC](https://www.ruby-forum.com/t/how-to-include-a-helper-method-in-a-controller/166199/2 "2009-04-23T07:55:17Z")

</div>

Did you try like  
include PhonenumberHelper  
in mailings\_controller.rb and  
is phonenumber\_helper.rb in app/helpers?

Sijo

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [April 23, 2009, 12:04pm UTC](https://www.ruby-forum.com/t/how-to-include-a-helper-method-in-a-controller/166199/3 "2009-04-23T12:04:09Z")

</div>

Thanks for your replies!

@ Sijo:  
The problem was resolved by adding “include PhonenumberHelper” in the  
controller, as you have suggested (I was sure I had done that before…)

@ bushfreakz:  
Any helpers in app/helpers are only available to views, by default. If  
you have “helper :all” in ApplicationController, all helpers in  
app/helpers are available to all _views_ only.

---

<div class="post-metadata">

**Author:** ![tharrisx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e19adc/32.png) [@tharrisx](https://www.ruby-forum.com/u/tharrisx)\
**Post date:** [April 23, 2009, 9:08am UTC](https://www.ruby-forum.com/t/how-to-include-a-helper-method-in-a-controller/166199/4 "2009-04-23T09:08:43Z")

</div>

hello im very new to rails but i “think”  
it should go in the mailings\_helper instead of the phonenumber\_helper

or there should be an application\_helper which i think is universal
