2016-11-07 76 views
0

標題可能不準確,但如何在下拉菜單的循環中增加日期?在下拉菜單中增加7天

控制器(簡單):

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

創建日期範圍時,請僅選擇與第一天具有相同週日值的日期。這給你第一次約會,第八次約會,第15次約會......

@arr = (f.start_date..f.end_date).to_a.select{|day| day.wday == f.start_date.wkday}