Reputation: 2011
I have model that isn't reliant on a database. It fetches data using a SOAP API. When editing and object, my date selector automatically resets to the current day, instead of using the value returned via the API. How do I get my date_select form helper to use the date supplied via said API?
form:
<%= date_select :start_time, :created, {:add_month_numbers => true } %>
edit action:
.....
@keyword = Keyword.new
@keyword.id = @result[0][:value]
@keyword.name = @result[1][:value]
@keyword.keyword = @result[2][:value]
@keyword.message1 = @result[3][:value]
@keyword.message2 = @result[4][:value]
@keyword.start_time = @result[5][:value]
the value of @result[5][:value] looks like "yyyy-mm-dd" and is returned as a string.
How can I get my date_select to properly reflect this value?
Upvotes: 0
Views: 262
Reputation: 8807
Use the :default option to set the default date:
<%= date_select :start_time, :created, :add_month_numbers => true, :default => Time.parse(@keyword.start_time) %>
Upvotes: 1