Reputation: 73
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?
Upvotes: 1
Views: 100
Reputation: 43298
extend ActionView::Helpers::DateHelper
in your model30.mins.from_now
to 30.minutes.from_now
I just tried it myself and have no problem doing the following:
class MyModel < ActiveRecord::Base
extend ActionView::Helpers::DateHelper
def self.update_status
event_time = time_ago_in_words(30.minutes.from_now)
Twitter.update("Event is starting in #{event_time}")
end
end
You have to use extend
instead of include
. See this article for an explanation.
Upvotes: 1