views:

50

answers:

2

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?

A: 

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

Jakub Hampl
A: 

There is no :value option for date_select. In your example, the value of the dropdowns will be obtained from the start_date attribute of whatever object you passed in when you started the form builder f.

On this object, you can simply set the start_date attribute before rendering, even if you're not actually saving it there.

There's also a select_date helper, which is the variant that is not linked to an object, and just allows you to pass a value. But that requires more manual labor, because it doesn't work out of the box with update_attributes.

Shtééf