エラーが発生しています
"2013-03-06" の未定義メソッド `strftime':String
strftime.
私のindex.html.erbでこれを行う行は次のようになります
<td><%= task.duedate.strftime("%B %e, %Y") %></td>
私は Rails を学んでいるばかりなので、それは愚かな初心者のエラーであると確信しています。ありがとうございました
エラーが発生しています
"2013-03-06" の未定義メソッド `strftime':String
strftime.
私のindex.html.erbでこれを行う行は次のようになります
<td><%= task.duedate.strftime("%B %e, %Y") %></td>
私は Rails を学んでいるばかりなので、それは愚かな初心者のエラーであると確信しています。ありがとうございました
strptime も使用できます。それは私のために働いています:)
DateTime.strptime(task.duedate ,"%B %e, %Y")
私もこの問題に直面し、データをデータベースに保存する前に create 関数でこのメソッドを呼び出して、文字列形式から datetime オブジェクトに日付を変換する controller.rb ファイルでメソッドを作成した後に解決できました。
def convert_to_date(date_as_string)
#expecting date format in "yyyy-mm-dd" format
if date_as_string.length > 0
split_date = date_as_string.split('-')
return Date.new(year=split_date[0].to_i, month=split_date[1].to_i,
day=split_date[2].to_i)
else
return nil
end
end