将 time_ago_in_words 应用于 class

Apply time_ago_in_words to a class

我有一个包含三列的 table,我很难添加 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}?"

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

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