Set the default value for the date selector in the phoenix frame to the current date

In the application that I am developing, I have a date switch that will be used mainly with the current date as a value (or a date in a few days). To reduce the work for my users, I want to set today's date as the default.

I can easily set the year: date_select f, :date, class="form_control", year: [options: @current_year, @current_year+1] but they could not do something like that for a month and a day.

I tried changing the code to date_select f, :date, class="form_control", year: [options: @current_year, @current_year+1], month: [default: 2], date_select f, :date, class="form_control", year: [options: @current_year, @current_year+1], month: [default: "2"] date_select f, :date, class="form_control", year: [options: @current_year, @current_year+1], month: [default: "02"] but none of them worked. Replacing defaultwith valuedid not matter. What mistake am I making?

Thanks in advance

+4
source share
2 answers

date_select. :

date_select f, :date, default: {@current_year, 2, 13}

, , , . datetime_select .

+6

, - , ,

<%= datetime_select f, :start, class: "form-control", 
default: {{@current_year, @current_month, @current_day}, 
{@current_hour, @current_minute, @current_second}} %>
0

All Articles