Forum: Ruby on Rails Cannot use view helpers in RJS helpers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
833fbd3f58a8ebbeb43756e8634334ed?d=identicon&s=25 Nicholas Henry (Guest)
on 2006-04-08 22:19
(Received via mailing list)
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
2ccb2f7699267d258faaafce4ee997df?d=identicon&s=25 Cody Fauser (Guest)
on 2006-04-10 01:23
(Received via mailing list)
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 Henry <nicholas.henry@gmail.com> wrote:
>
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Cody Fauser
http://www.codyfauser.com
833fbd3f58a8ebbeb43756e8634334ed?d=identicon&s=25 Nicholas Henry (Guest)
on 2006-04-10 18:27
(Received via mailing list)
Brilliant! Thanks :)
This topic is locked and can not be replied to.