Cannot use view helpers in RJS helpers


#1

Any ideas why I would get an error in a RJS helper on view helpers
such as number_to_currency.

Example:

my_template.rjs

page.help_me

my_helper for my_controller

def help_me
number_to_currency(10)
end

I have also tired page.number_to_currency but that doesn’t work either.

Cheers,
Nicholas


#2

It has to do with the scope of the helper. The ActionView::Helpers
modules aren’t included into the context the RJS helper method is
executed in. You can manually include the helpers you want into your
module like so:

module ExpensesHelper
include ActionView::Helpers::NumberHelper

def help_me
number_to_currency(10)
end
end

On 4/8/06, Nicholas H. removed_email_address@domain.invalid wrote:

Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Cody F.
http://www.codyfauser.com


#3

Brilliant! Thanks :slight_smile: