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: 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.boling@gmail.com * blog: http://galtzo.blogspot.com/ * languages: English, Spanish, Portuguese ***********************************************************)
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 <peter.boling@gmail.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: > 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.boling@gmail.com > * blog: http://galtzo.blogspot.com/ > * languages: English, Spanish, Portuguese > ***********************************************************) > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060815/9c93555c/attachment.html
On 8/14/06, Kyle Slattery <slattery@fidgeting.net> wrote:> I believe it is because a helper by definition is only available for use in > your view, not in your controller. > > -KyleYou 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.boling@gmail.com * blog: http://galtzo.blogspot.com/ * languages: English, Spanish, Portuguese ***********************************************************)