0

我选择

m_repeats = Event.all

然后我需要更改每个元素中的时间段(它是日期字段)。我需要为当前(日期)设置年份和月份

我尝试这样做:

m_repeats.map{ |elem| elem.schedule.year = date.year, elem.schedule.month = date.month } 

但我得到错误:

undefined method `month=' for Wed, 03 Apr 2013:Date

我如何通过地图更改它们?

4

1 回答 1

1

There is no 'month=' method for Date class. I guess this will work,

m_repeats.map{ |elem| elem.schedule = Date.new(Date.today.year, Date.today.month, elem.schedule.day)} 
于 2013-04-04T12:11:26.697 回答