How call distance_of_time_in_words() from controller?

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

  include ActionView::Helpers::DateHelper

That's what I needed; it worked; thanks!!!

You shouldn’t really need to call this within a controller. Rails uses a convention called MVC which means that the model, the view, and the controller concerns are all separate to themselves. Here’s the wikipedia article on it [http://en.wikipedia.org/wiki/Model-view-controller] and here’s an entry in the Rails’ wiki for it as well [http://wiki.rubyonrails.org/rails/pages/UnderstandingMVC]. It’s a really core convention in rails. distance_of_time_in_words is purely a view concern because it’s about output which is the view. The standard way to do this is to render a template [view] instead of constructing a string directly in the controller. Hope that helps.

RSL

It looks to me like you can subtract one date var from another & get a Rational that represents the number of days difference. You should be able to .to_i that to work w/it as a number.

HTH,

-Roy

Roy Pardee wrote:

It looks to me like you can subtract one date var from another & get a Rational that represents the number of days difference. You should be able to .to_i that to work w/it as a number.

Thanks, Roy. You are quite right. The reason it wasn't working for me before was that I was making a silly ruby-n00b mistake of using the symbols for the member variables, rather than the variables themselves! ( :completed - :due instead of completed - due) I didn't do that anywhere else so I don't know what I was thinking.