How to work with date_select form helper without a model in Rails?
I have a variable @the_date
and a date_select form helper without an associat开发者_如何学Goed model.
How to use date_select
to display the appropriate HTML?
The following does not work:
<%= date_select "the_date", @the_date %>
You can do:
<% @the_date = Time.now %>
<%= date_select("my_date", "my_date", :default => @the_date) %>
Here's what finally worked:
<% @the_date = Date.strptime(@the_date_string, "%Y-%m-%d") %>
<%= date_select("the_date_string", "", :default => @the_date) %>
I am storing the date as a string. So, it needs to be converted to a date object before displaying in the HTML form, and converted back to a string before saving in the database.
精彩评论