Search code examples
rubyhamltimeago

Apply time_ago_in_words to a class


I have a table with three columns and am having difficulty in adding time_ago_in_words to follow the document name in the same cell.

I have tried a couple different iterations of %td= document.name, time_ago_in_words(document.created_at) to no avail.

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}?"

Solution

  • You can use ruby string interpolation in HAML:

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