我有两个关于未定义方法`distance_of_time_in_words'
的问题在我看来,我正在尝试这个,并获得未定义的方法:
<td><%= distance_of_time_in_words (patient_course_step.started, patient_course_step.completed) %></td>
我真的想在我的模型中使用它为我的模型创建一个“辅助方法”。
模型中的辅助方法示例:
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
答案 0 :(得分:0)
尝试使用your_object_name.distance
。它应该工作
答案 1 :(得分:-1)
这样做并不好,但我理解它的必要性。请参阅this snippet on DZone了解如何操作。