Search code examples
ruby-on-railsruby-on-rails-3activerecordruby-on-rails-3.2scaffolding

Leaving date/time blank in Rails datetime_select


Is there an easy way to have the option to not specify a date or datetime in a Rails form that uses datetime_select, date_select or time_select? By default, the fields are set at the current date/time and there's no way to not choose a date/time.

Using Rails 3.2.8


Solution

  • What you want is the include_blank option: (Nil value on datetime_select?)

    f.datetime_select :attr_name, include_blank: true