drop-down selects the first value of the list in edit mode


I have a drop down select that is set up like below:

<%= select_tag :city_id, option_groups_from_collection_for_select(@regions, :cities, :name, :id, :name) %>

It works fine, except that when I load the edit view the list loads the first item in the select, not the saved value. Is there parameter I'm missing? On rails 4.

According to the documentation on option_groups_from_collection_for_select found here: http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/option_groups_from_collection_for_select
It has a sixth parameter that is the selected value, so just add the last parameter with the value you want and it will work:

<%= select_tag :city_id,
  option_groups_from_collection_for_select(@regions, :cities, :name, :id, :name, "your_city") %>