Thursday, February 09, 2017

How to set default date in date_select of Rails 5

You can use the selected option to specify the default date.

    <%= f.date_select :published_at, order: [:month, :day, :year], start_year: Date.current.year - 5, end_year: Date.current.year + 1, selected: @date %>

In my case, I set it in the controller to today's date:

@date = Date.today