-1

My Ruby app is showing the beginning of the month (day 1) when processing:

start_month => Date.today.month

I would like the end of the month, so I changed it to:

start_month => Date.today.end_of_month

but it is showing the beginning of the month. Would you know why?

Based on the comments, I rewrote as follows, yet it still does not work. I am sure I am misspelling something

<div class="field">
  <%= f.label :delivered_at, "Estimated delivery"  %><br />
  <%= f.date_select(:delivered_at.end_of_month, :start_year => Date.today.year, :start_month => Date.today.end_of_month,:prompt => { :month => 'Choose month', :year => 'Choose year'}, :discard_day => true) %>
</div>
4

2 回答 2

0

鉴于您显示的视图的代码,我猜您的问题出在您的控制器代码中。如果您查看 的文档f.date_select丢弃日期会使其默认为该月的第一天。除非你在控制器中做某事delivered_at,否则它总是一个月的第一天,所以你需要delivered_at.end_of_month在保存模型之前将其更改为。

于 2013-11-13T17:47:20.697 回答
0
Date.today.to_date.end_of_month

输出 :

Sat, 30 Nov 2013

Date.today.to_date.end_of_month.month

输出:

11
于 2013-11-13T18:56:43.897 回答