0

如何使用 HAML 做这样的事情:

<%= Student.name %> and <%= Student.age %> are required.

或者在我的具体情况下:

%tbody
  - @quotes.each do |quote|
    %tr
      %td= time_ago_in_words quote.created_at ago

如果你仔细观察,我只是想输出“2 个月前”而不是“2 个月”

谢谢您的帮助!

4

1 回答 1

3

您不能在 HAML 中“结束一行代码”,但您可以通过多种方式组合代码和纯文本:

  1. 字符串插值:

    %td #{time_ago_in_words quote.created_at} ago
    
  2. 级联:

    %td= time_ago_in_words(quote.created_at) + " ago"
    
  3. 文本/代码行的分隔:

    %td
      = time_ago_in_words quote.created_at
      ago
    
于 2013-08-06T20:59:45.913 回答