Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails -- Can't set value for date_select in form

I'm pulling data from an API where the date data comes in as "2008-02-11 00:00:00 "

I would like that data to go into my form within the date_select as a value so I can view it correctly before I add it into my database.

The view looks like

<%= f.label :start_date %><br />
<%= f.date_select :start_date, :value => " #{@stdate[idx]} " %>

The object is actually an array of dates since I'm doing this action several times do thats why the [idx] is there; serving as an index.

<%= @stdate[idx] %> ends up outputting "2008-02-11 00:00:00 " but the fields for the date_select helper only outputs the current date "2010" "June" "5" in those dropdown date selects fields...

Do I need to set the values of the Year, Month, and Date Individually? I have Chronic and tried to parse the object before using it as a value for the date_select and that didnt work either.

Any ideas?

like image 321
ChrisWesAllen Avatar asked Jan 22 '26 04:01

ChrisWesAllen


1 Answers

You wouldn't use the :value option but the :default option and pass a DateTime object to it.

like image 76
Jakub Hampl Avatar answered Jan 24 '26 22:01

Jakub Hampl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!