1

我的模型中有一个日期字段。

我正在尝试生成这样的数组[6/29/13, 6/27/13]

但是,当我使用.collect它时,它会返回一个这样的数组[Sat, 29 Jun 2013, Thu, 27 Jun 2013]

@dates = Todo.all.collect(&:date)

我怎样才能遍历所有的数据库项目和:

  1. 将日期转换为速记
  2. 将所有内容保存到数组中

我试过用.strftime("%m/%d/%y")但没有太多运气。

4

1 回答 1

0
Todo.all.map { |todo| todo.date.strftime("%m/%d/%y") }
于 2013-06-30T07:40:45.807 回答