You probably want to put the method in the application controller,
then call helper_method on it.
class ApplicationController < AcionPack.....whatever
helper_method :my_method
def my_method
end
end
This makes it available to both view and controller. You could
probably also include the view helper in the controller, but I
wouldn''t advise it as it goes counter to mvc and the way things are
usually done around here.
Brian
On 4/18/05, Gavin Sinclair
<gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org>
wrote:> On Tuesday, April 19, 2005, 4:33:34 AM, Pat wrote:
>
> > I have a method in an application helper that works fine in the views,
> > but I''d like to use it in the controller as well.
>
> > I require the file, and then reference the method with
> > ApplicationHelper::method_name, but it says that it''s an
undefined
> > method for ApplicationHelper:Module. How can I use the helper within
> > my controller?
>
> I believe
>
> class XyzController
> ...
> helper_method :foo
> ...
> end
>
> is what you want. It will make the method ''foo'' from the
XyzHelper
> available in the controller.
>
> (That may be wrong, but it''s close; check API docs for details.)
>
> Gavin
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
The years ahead pick up their dark bags.
They move closer. There''s a slight rise in the silence
then nothing.
--
(If you''re receiving this in response to mail sent to
bluczkie-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org, don''t be concerned
This is my new address,
but mail will be forwarded here indefinitely)