I have a (cut-down) Model which looks like this:
class MyModel < ActiveRecord::Base
def self.update_status
event_time = time_ago_in_words 30.minutes.from_now
Twitter.update("Event is starting in #{event_time}")
end
end
As expected, I am getting a NoMethodError exception due to trying to use a method ‘time_ago_in_words’ from DateHelper. How should I accomplish this, and maybe more importantly, am I going about this the correct way?
extend ActionView::Helpers::DateHelperin your model30.mins.from_nowto30.minutes.from_nowI just tried it myself and have no problem doing the following:
You have to use
extendinstead ofinclude. See this article for an explanation.