date_field_tag, how i set up a default date? [Ruby on rails]

CesarWelch picture CesarWelch · Jun 23, 2014 · Viewed 6.9k times · Source

I wanted to set a default date, the actual date for example, how i set it up?

<%= date_field_tag(:datetime_ida, value = nil, options = {})%>

Also how can i set up a default value in a combo box

<%= select_tag :children_quantity, options_for_select([['0 Children', 0], ['1 Children', 1], ['2 Children', 2], ['3 Children', 3], ['4 Children', 4], ['5 Children', 5]], 1) %>

and by the way, what's the difference between date_field_tag and the date_field?

Answer

Sachin Singh picture Sachin Singh · Jun 23, 2014

try this out:

  <%= date_field_tag(:datetime_ida, Date.today)%>

pass the default date as second parameter.

   you correctly set the default value of combo box as shown in your question.