2013-08-06 35 views
0

如何做一個像這樣使用HAML:結束了一行代碼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個月」

感謝您的幫助!

回答

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 
    
+0

很好的回答!感謝您展示所有不同的方式來做到這一點!第三種選擇是我正在尋找的!再次感謝! – Arel