I have two questions about undefined method `distance_of_time_in_words’
In my view I am attempting this, and get undefined method:
<td><%= distance_of_time_in_words (patient_course_step.started, patient_course_step.completed) %></td>
I really want to use this in my model to create a “helper method” for my model.
Examples of helper methods in model:
def duration
distance_of_time_in_words (self.started, self.completed)
end
def status
if started.nil?
created_at_formated = created_at.strftime("%B %d, %Y, %l:%M %p")
return "Not started assigned on #{created_at_formated}"
elsif !completed.nil?
completed_formated = completed.strftime("%B %d, %Y, %l:%M %p")
return "Completed at #{completed_formated}"
else
last_viewed_formated = last_viewed.strftime("%B %d, %Y, %l:%M %p")
return "In Progress, last viewed at #{last_viewed_formated}"
end
end
- How can I get distance_of_time_in_words to work in my view
- Is it a good practice to have helper methods in a model (as shown above)
It’s not good practice to do this, but I understand the need for it. See this snippet on DZone on how to do it.