I have the following code in views/posts/show.html.erb:
<span><%= @post.time_ago_in_words(Time.now) %></span><br />
And I get this error:
undefined method `time_ago_in_words' for #<Post:0xac200b0>
Any suggestions to fix this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
time_ago_in_words is an Helper. It’s not an ActiveModel instance method. So you have to call it this way(the field is up to you):
By the way, calculating this kind of stuff is not a best practise. I recommend you to take a look at a solution like jquery.timeago.