Problem with date_select when using :discard option. (Rails)
Posted
by MikeH
on Stack Overflow
See other posts from Stack Overflow
or by MikeH
Published on 2010-03-23T17:25:57Z
Indexed on
2010/03/24
3:03 UTC
Read the original article
Hit count: 311
I'm using a date_select
with the option :discard_year => true
If a user selects a date in the date select, and then he comes back and returns the select to the prompt values of Month and Day, Rails automatically sets the select values to January 1.
I know this is the intended functionality if a month is selected and a day is left blank, but that's not the case here. In my example, the user sets both the month and day back to the prompt. By Rails forcing January 1, I'm getting bad results.
I've tried every parameter available in the api. :default => nil, :include_blank => true. None of those change the behavior I'm describing.
I've isolated the root of the problem, which is this:
Because I'm discarding the :year parameter, when the user tries to return the month and day to the prompt values, Rails doesn't see an empty prompt select. It perhaps sees a year selected with empty month and day, which it then sets to January 1. This is the case because the :discard_year parameter does in fact set a date in the database, it just removes it from the view.
How can I code around this problem?
© Stack Overflow or respective owner