Alex Rivera | Logout

Nil value on datetime_select?

Asked 2009-02-18T02:04:37.603
11

When using <%= f.datetime_select :start %> for a "new" object form, how can you set the options to not select a date by default but rather a nil/null value? The field in the related model can optionally be null but by default the datetime_select control doesn't have a null option.

Edit
Report

1 Answer

0

You'll want to use the :prompt option.

from the Rails docs:

  # Generates a datetime select with a custom prompt. Use :prompt=>true for generic prompts.
  datetime_select("post", "written_on", :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'})
  datetime_select("post", "written_on", :prompt => {:hour => true}) # generic prompt for hours
  datetime_select("post", "written_on", :prompt => true) # generic prompts for all
answered 2009-02-18T03:08:05.097

Your Answer