Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何在主干模板中使用rails time\u ago\u in\u words_Jquery_Ruby_Ruby On Rails 4_Backbone.js_Hamlc - Fatal编程技术网

Jquery 如何在主干模板中使用rails time\u ago\u in\u words

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=

有没有一种方法可以使用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=[]
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