underScorePassionFruit
underScorePassionFruit

Reputation: 325

how do I use rails time_ago_in_words in backbone template

Is there a way to use rails standard methods such as time_ago_in_words in backbone template also using hamlc ? When I tried this

.created_at= time_ago_in_words e.created_at

It throws an exception

Uncaught ReferenceError: time_ago_in_words is not defined

Upvotes: 0

Views: 126

Answers (1)

underScorePassionFruit
underScorePassionFruit

Reputation: 325

    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

Upvotes: 0

Related Questions