# ActionPack: number\_to\_phone error

**URL:** <https://www.ruby-forum.com/t/actionpack-number-to-phone-error/64936>\
**Category:** Rails\
**Created:** [August 15, 2006, 2:20pm UTC](https://www.ruby-forum.com/t/actionpack-number-to-phone-error/64936 "2006-08-15T14:20:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [August 15, 2006, 2:20pm UTC](https://www.ruby-forum.com/t/actionpack-number-to-phone-error/64936/1 "2006-08-15T14:20:48Z")

</div>

Question about the number\_to\_phone function as provided by rails in  
actionpack:

> **[ActionView::Helpers::NumberHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html)**
>
> Provides methods for converting numbers into formatted strings. Methods are provided for phone numbers, currency, percentage, precision, positional notation, file size, and pretty printing.

If I do this in my controller:  
num = number\_to\_phone(params[:phone\_number])  
I get this error:  
undefined method `number\_to\_phone’ for  
#TicketsController:0xb7a2bfcc

Whereas if I do this in my view:  
\<% phone\_number = number\_to\_phone(@phone\_number.phone\_number) %\>  
\<%= text\_field ‘phone\_number’, ‘phone\_number’, {  
:value =\> phone\_number,  
:size =\> 12, } %\>

It works as advertized. Does anyone have any idea why?

## Thanks, Peter

(\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

- Peter H. Boling
- Web Application Designer - PanEther, LLC
- email: removed\_email\_address@domain.invalid
- blog: [http://galtzo.blogspot.com/](http://galtzo.blogspot.com/)
- languages: English, Spanish, Portuguese  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*)

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [August 15, 2006, 2:20pm UTC](https://www.ruby-forum.com/t/actionpack-number-to-phone-error/64936/2 "2006-08-15T14:20:49Z")

</div>

I believe it is because a helper by definition is only available for use  
in  
your view, not in your controller.

-Kyle

---

<div class="post-metadata">

**Author:** ![bodikp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@bodikp](https://www.ruby-forum.com/u/bodikp)\
**Post date:** [August 15, 2006, 4:47pm UTC](https://www.ruby-forum.com/t/actionpack-number-to-phone-error/64936/3 "2006-08-15T16:47:43Z")

</div>

On 8/14/06, Kyle S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I believe it is because a helper by definition is only available for use in  
> your view, not in your controller.
> 
> -Kyle

You are correct. That’s what it was.  
Adding this to my controller (application.rb or an individual  
controller) made it available:  
include ActionView::Helpers::NumberHelper

## Thanks!

(\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

- Peter H. Boling
- Web Application Designer - PanEther, LLC
- email: removed\_email\_address@domain.invalid
- blog: [http://galtzo.blogspot.com/](http://galtzo.blogspot.com/)
- languages: English, Spanish, Portuguese  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*)
