Is there a way to use date_select in the form_for helper and have the
displayed date in the drop-down list be something besides “today”? I’m
trying to get it to be “yesterday” without success. I also tried
<% d = Date.today %>
<% d = d-1 %>
<%= select_date (date=d) %>
I assume you’re trying to have a date field default to yesterday in
the form if it hasn’t already been set by the user? Try setting it to
yesterday in the controller. So if you have an ActiveRecord object
called event that includes an attribute called scheduled_date, do
something like this in the controller action:
event.scheduled_date ||= 1.day.ago
Now you should be able to use the form_for/date_select and get the
right result. Alternatively, you could use the select_date helper…
should look something like:
Is there a way to use date_select in the form_for helper and have the
displayed date in the drop-down list be something besides “today”? I’m
trying to get it to be “yesterday” without success. I also tried
<% d = Date.today %>
<% d = d-1 %>
<%= select_date (date=d) %>
The notation select_date(date = Date.today, options = {}) means - if
there is no parameter supplied it uses Date.today as first parameter and
an empty hash as options.
Stefan
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.