Acrux Acrux - 1 year ago 46
Ruby Question

How to use srtftime in views

I am getting an error with

strftime
.

My views look like:

<%=room.date%>
works and yields "2017-07-27".

However, I want to convert this to July 27, 2017.

<%= Date.parse(room.date).strftime("%B %e, %Y ") %>
does not work and causes the following error: "ActionView::Template::Error (no implicit conversion of Date into String)":

My schema is:

t.date "date"


I don't know what I am doing wrong. Thanks!

Answer Source

If your room.date is type of date you shouldn't try to parse it. So I'd suggest first try to use <%= room.date.strftime('%B %e, %Y'). Please comment below if that wont work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download