标题可能不准确,但如何在下拉菜单的循环中增加日期?
控制器(简单):
f = Foo.find(1)
f.start_date = Date.today
f.end_date = 30.days.from_now
f.save
@arr = *(f.start_date..f.end_date)
查看:
<select class="ui dropdown">
<option value="">Select work week</option>
<% @arr.each do |a| %>
<option value="<%= a %>"><%= a %> to <%= (a + 7.days) %></option>
<% end %>
</select>
预计下拉列表:
(today) to (7th day)
(8th day) to (15th day)
...
...
(last day)
如何解决这个问题?
答案 0 :(得分:0)
创建日期范围时,仅选择与第一天具有相同工作日值的日期。这给你第一个日期,第八个日期,第15个日期......
@arr = (f.start_date..f.end_date).to_a.select{|day| day.wday == f.start_date.wkday}