Ask A Question


You’re not receiving notifications from this thread.


Jacob Hedengren asked in General

Hi everyone,

I have recently set on a mission to learn more about APIs. I get some data from a external JSON API but have come a cross an issue that I need some help with.

I’ve defined my cars variable in my controller and set it to

def index 
    @cars = HTTParty.get('...

I am then looping through each car in my view with

<% @cars.each do |car| %>
    <%= car[“date”] %>
<% end %>

The result in my view;


How can I change this format to instead say time_ago_in_words?

Thanks alot in advance!

/ Jacob


This will do it.

#=> "1 day, 8 hours, and 32 minutes"

Thanks John! Worked perfectly!

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 76,990+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2023 GoRails, LLC. All rights reserved.