Using helpers in controllers

Hi,
What’s the recommended method of accessing helper methods from
controllers?
For example, if I wanted to use the pluralize method from
ActionView::Helpers::TextHelper in one of my controllers for flash
messages, how would I make it accessible?

Many thanks,
Jordan

Jordan E. wrote:

Hi,
What’s the recommended method of accessing helper methods from
controllers?
For example, if I wanted to use the pluralize method from
ActionView::Helpers::TextHelper in one of my controllers for flash
messages, how would I make it accessible?

Many thanks,
Jordan

Because the use of helpers is discouraged in controllers (as you are
supposed to use them on views) is a little hard to do that. One option
could be:

aht= ActionView::Helpers::TextHelper

aht.module_eval do
module_function :pluralize
end

Then you could do:

flash[:notice]= aht.pluralize(“thing”)

Not very nice tough… :slight_smile:

Then you could do:

flash[:notice]= aht.pluralize(“thing”)

Not very nice tough… :slight_smile:

No, but I’ll give it a try :slight_smile:
Thanks.