You could do it this way.
class MyController
include ActionView::Helpers::DateHelper
def some_method
distance_of_time_in_words ...
end
end
I think this would also work, and would be better since it wouldn't be
adding all of DateHelper's methods to the controller:
def some_method
@template.distance_of_time_in_words ...
end
-Dan
http://www.dcmanges.com
On Sep 7, 12:30 pm, Peter Alvin <[EMAIL PROTECTED]>
wrote:
> How call distance_of_time_in_words() from a controller instead of a
> view?
>
> Reference:http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html...
>
> This page says this method is in: Module ActionView::Helpers::DateHelper
>
> which also says is here:
>
> in: actionpack/lib/action_view/helpers/date_helper.rb
>
> BUT, HOW IN THE WORLD do I get that included in my controller file?
>
> 1) This doesn't work inside the class definition:
>
> require "date_helper"
>
> as I get this message:
>
> MissingSourceFile in MyController#datePage
>
> no such file to load -- date_helper
>
> 2) THEN, when I try this:
>
> helper :date_helper
>
> I get this:
>
> Missing helper file helpers/date_helper_helper.rb
>
> Please help! I bet this is cake if I just know the solution.
>
> Thanks very much in advance,
>
> Pete
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---