如何在骨干模板中使用rails time_ago_in_words

时间:2015-10-22 14:54:39

标签: jquery ruby ruby-on-rails-4 backbone.js hamlc

有没有办法在主干模板中使用rails标准方法,例如time_ago_in_words,也使用hamlc?我试过这个时

.created_at= time_ago_in_words e.created_at

抛出异常

Uncaught ReferenceError: time_ago_in_words is not defined

1 个答案:

答案 0 :(得分:0)

    I had to create this simple method and return to the template. 

     include ActionView::Helpers::DateHelper
     def personalize_time(c)
          coll = []
          c.each do |v|
            coll << {"created_at" => time_ago_in_words(v['created_at']), "collection" => v}         
          end
          coll
     end