select tag . Default value rails

<%= select_tag(:city, options_for_select([['New York', 1], ['San Francisco', 2], ['Seattle', 3]], params[:city]), prompt: 'Select a city') %>

Explanation:

  1. <%= ... %>: Embeds Ruby code into the HTML ERB file for execution.

  2. select_tag(:city, ...):

  3. select_tag: Generates an HTML select dropdown element.
  4. :city: Symbol used as the name for the select dropdown.

  5. options_for_select([['New York', 1], ['San Francisco', 2], ['Seattle', 3]], params[:city]):

  6. options_for_select: Constructs the options for the select dropdown.
  7. [['New York', 1], ['San Francisco', 2], ['Seattle', 3]]: Array of arrays containing city names and corresponding values.
  8. params[:city]: Sets the selected option based on the value of params[:city].

  9. prompt: 'Select a city':

  10. prompt: Adds a default prompt option to the dropdown with the specified text 'Select a city'. ```