i have got a problem in my project. i have f.date_select field in my
form and i want to set the default date = current date+30. but
f.date_select is not allowing me to do so. there are options to set year
only not month and day.
see what i have followed:
If this for new records, which it sure does sound like, Denise's idea is
spot on. Just set it in the object when you create it and don't futz
with the rest.
What would you do if this is for an existing record?
I have nearly the same issue, but the problem for me is that the
existing record is currenty null, and the date_select seems to be
defaulting to today for its date.
What would you do if this is for an existing record?
I have nearly the same issue, but the problem for me is that the
existing record is currenty null, and the date_select seems to be
defaulting to today for its date.
Dustin
On Jun 4, 5:05�pm, Phillip Koebbe <rails-mailing-l...@andreas-s.net>
Hello Dustin,
You can do two things. If you must have a date in the form, then do the
same thing for the existing record as you do for the new one: set it in
the controller. Otherwise, if the date can actually be blank, add
:include_blank => true to the f.date_select statement.
Keep in mind that when using form_for, and therefore the f.* notation,
FormBuilder will associate the date selector with the valid_til method
on whatever object you pass into form_for. When initialized, whatever
value you have in object.valid_til will be used to set the date
selector's date. If valid_til is nil, the current date will be used,
unless :include_blank is true, and then it will be blank.
It worked great - I am quickly becoming a rails convert (this would
have really sucked in php).
This was what finally did what I sort of expected:
<p>Date of Birth: <%= f.date_select :customers_dob, :start_year =>
1920, :use_month_numbers => true, :include_blank => true %></p>