ruby on rails - drop down select switches to first value in list in edit mode -


i have drop down select set below:

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

it works fine, except when load edit view list loads first item in select, not saved value. there parameter i'm missing? on rails 4.

according documentation on option_groups_from_collection_for_select found here: http://apidock.com/rails/actionview/helpers/formoptionshelper/option_groups_from_collection_for_select
has sixth parameter selected value, add last parameter value want , work:

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

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -