将time_ago_in_words应用于课程

时间:2015-04-11 21:06:03

标签: ruby haml timeago

我有一个包含三列的表格,并且很难添加time_ago_in_words以跟踪同一单元格中的文档名称。

我尝试了几次不同的%td= document.name, time_ago_in_words(document.created_at)迭代但无济于事。

HAML:

%table.table.table-striped
    %thead
      %tr
        %th Name
        %th Download Link
        %th  
    %tbody
      - @documents.each do |document|
        %tr
          %td= document.name
          %td= link_to "Download Document", document.attachment_url
          %td= button_to "Delete",  document, method: :delete, class: "btn btn-danger", confirm: "Are you sure that you wish to delete #{document.name}?"

1 个答案:

答案 0 :(得分:1)

您可以在HAML中使用ruby字符串插值:

%td="#{document.name}, #{time_ago_in_words(document.created_at)}"