我收到strftime
的錯誤。如何在視圖中使用srtftime
我的看法是這樣的:
<%=room.date%>
其作品併產生 「2017年7月27日」。
但是,我想將其轉換爲「2017年7月27日」。
<%= Date.parse(room.date).strftime("%B %e, %Y ") %>
不工作,導致以下錯誤:
ActionView::Template::Error (no implicit conversion of Date into String)
我的模式是:
t.date "date"
我不知道我做錯了事情。謝謝!
錯誤未再出現,但日期未顯示。不知道爲什麼。 – Acrux
如果你需要在視圖中打印這樣的值,那麼你可以使用'room.date.strftime(「%B%e,%Y」)'作爲@knut提到的,試試看。 –