How do I render timestamps for my phoenix endpoint??

I’m using phoenix as an API that serves JSON… I have a controller action that looks like this…

def index(conn, _params) do
    blogs = Resources.list_blogs()
    # IO.inspect blogs
    render(conn, "index.json", blogs: blogs)
  end

When I inspect the blogs, just before the render code, it shows that I have timestamps

but when it gets returned in my API client everything but the timestamps get returned.

I’m sure there’s some easy way to render the timestamps, what am I missing? Please help…

Do check your views for the controller and see if it has the timestamp tags in it.

If your controller is user_controller.ex, then check your views folder for the file user_view.ex. In the view file, add the timestamps to the render function that serves your index.json. Probably, index.json will be a recursive function pointing to return a single model of interest, which is where you need to add the timestamps.

1 Like

Oh wow. thanks a lot. I got the datestamps now :+1: :+1: :+1:

1 Like