Jquery 如何在主干模板中使用rails time\u ago\u in\u words
有没有一种方法可以使用rails的标准方法,例如time_ago_in_words in_主干模板也使用hamlc?当我尝试这个的时候Jquery 如何在主干模板中使用rails time\u ago\u in\u words,jquery,ruby,ruby-on-rails-4,backbone.js,hamlc,Jquery,Ruby,Ruby On Rails 4,Backbone.js,Hamlc,有没有一种方法可以使用rails的标准方法,例如time_ago_in_words in_主干模板也使用hamlc?当我尝试这个的时候 .created_at= time_ago_in_words e.created_at 它抛出一个异常 Uncaught ReferenceError: time_ago_in_words is not defined 我必须创建这个简单的方法并返回模板。 包括ActionView::Helpers::DateHelper def个性化时间(c) coll=
.created_at= time_ago_in_words e.created_at
它抛出一个异常
Uncaught ReferenceError: time_ago_in_words is not defined
我必须创建这个简单的方法并返回模板。
包括ActionView::Helpers::DateHelper
def个性化时间(c)
coll=[]
c、 每个都有| v|
coll time_ago_in_words(v['created_at']),“collection”=>v}
结束
科尔
结束
当然不是。除非您将rails helper:time\u ago\u in\u words重写为javascript函数。您最好使用momentjs来处理js中的日期/时间
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