List Info

Thread: ActionPack: number_to_phone error




ActionPack: number_to_phone error
user name
2006-08-14 21:19:01
Question about the number_to_phone function as provided by
rails in actionpack:
http://api.rubyonrails.org/classes/Action
View/Helpers/NumberHelper.html

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:      peter.bolinggmail.com
* blog:       http://galtzo.blogspot.co
m/
* languages:  English, Spanish, Portuguese
***********************************************************)
_______________________________________________
Rails mailing list
Railslists.rubyonrails.org
h
ttp://lists.rubyonrails.org/mailman/listinfo/rails
ActionPack: number_to_phone error
user name
2006-08-15 02:40:41
I believe it is because a helper by definition is only available for use in your view, not in your controller.

-Kyle

On 8/14/06, Peter Boling < gmail.com">peter.bolinggmail.com> wrote:
Question about the number_to_phone function as provided by rails in actionpack:
http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html

If I do this in my controller:
 &nbsp; &nbsp; &nbsp;num = number_to_phone(params[:phone_number])
I get this error:
&nbsp; &nbsp; &nbsp; undefined method `number_to_phone' for #<TicketsController:0xb7a2bfcc>

Whereas if I do this in my view:
&nbsp; &nbsp; &nbsp; &lt;% phone_number = number_to_phone(phone_number.phone_number) %>
&nbsp; &nbsp; &nbsp; <%= text_field 'phone_number', 'phone_number', {
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  :value => phone_number,
 &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; :size => 12, } %>

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

Thanks,
Peter
--
(**********************************************************
* Peter H. Boling
* Web Application Designer - PanEther, LLC
* email:&nbsp; &nbsp; &nbsp; gmail.com">peter.bolinggmail.com
* blog: ; &nbsp; &nbsp;  http://galtzo.blogspot.com/
* languages:  ;English, Spanish, Portuguese
***********************************************************)
_______________________________________________
Rails mailing list
lists.rubyonrails.org">Railslists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails

ActionPack: number_to_phone error
user name
2006-08-15 14:44:36
On 8/14/06, Kyle Slattery <slatteryfidgeting.net> 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:      peter.bolinggmail.com
* blog:       http://galtzo.blogspot.co
m/
* languages:  English, Spanish, Portuguese
***********************************************************)
_______________________________________________
Rails mailing list
Railslists.rubyonrails.org
h
ttp://lists.rubyonrails.org/mailman/listinfo/rails
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )