0
下面的代碼工作,只顯示,如果它是目前日期:顯示格式的日期如果存在的話,否則佔位符
f.text_field :published_at, placeholder: "E.g. 12 Sep 2014", value: @post.try(:published_at)
但我會怎麼格式化?
這是我怎麼會格式化,如果我知道的日期存在:
value: @post.published_at.strftime("%e %b %Y")
你約'@ post.try(:published_at)。嘗試(:strftime的「% e%b%Y「)'? – IS04 2014-09-24 12:44:25