Justin Bailey
2005-Sep-01 18:14 UTC
How to add an instance method from Actionview::Helpers to another module?
I''m using the CalendarHelper module, which generates a nice HTML
calendar. I would like to be able to access the "link_to_remote"
method in the ActionView::Helper module. Unfortunately, the
CalendarHelper module is included in my controller, not in any of my
views, so I do not have direct access to it. I have been trying to
include the instance method direclty into the CalendarHelper module
but without much luck.
For example, doing it this way:
module CalendarHelper
require
''/vendor/rails/actionpack/lib/action_view/helpers/javascript_helper''
include ActionView::Helpers
module_function ("ActionView::Helpers::link_to_remote".intern)
...
end
Produces the error:
uninitialized constant CalendarHelper
which occurs in the controller including the CalendarHelper module. If
I remove the ''require'' line I get this kind of error:
undefined method `ActionView::Helpers::link_to_remote'' for module
`CalendarHelper''
which in this case occurs directly in the CalendarHelper module.
Any suggestions on how to do this, or a better way to do it? Thanks
for any help.
Justin
Doug Beatty
2006-Mar-29 02:20 UTC
[Rails] Re: How to add an instance method from Actionview::Helpers to another module?
Justin Bailey <jgbailey@...> writes:> > I''m using the CalendarHelper module, which generates a nice HTML > calendar. I would like to be able to access the "link_to_remote" > method in the ActionView::Helper module. Unfortunately, the > CalendarHelper module is included in my controller, not in any of my > views, so I do not have direct access to it. I have been trying to > include the instance method direclty into the CalendarHelper module > but without much luck. >I found this suggestion at http://wiki.rubyonrails.org/rails/pages/HowtoWorkWithHelpers: Note Remember that helpers can?t be used in the controller! If you need a method both in a view and a controller, define them in the controller and export them via helper_method() .