Answer the question
In order to leave comments, you need to log in
Rails 4. How to make a loadable value from the database?
Good afternoon,
In one of the forms I have a select field that contains the following construction:
<%= f.select :dic_country_id, options_from_collection_for_select(@countries, "id", "country_name") %>
You can select a country in the field, let's say Russia , then saved successfully. The next time the form is accessed, the country selection list reappears in alphabetical order, and I need the value from the database to be loaded into the select field (i.e. the starting point was Russia, not Abkhazia, because it is the first in alphabetical order) .
Thank you in advance
Answer the question
In order to leave comments, you need to log in
If you want from the database, then try to set the value yourself as the fourth parameter for options_from_collection_for_select
Something like this:
<%= f.select :dic_country_id, options_from_collection_for_select(@countries, "id", "country_name", значение_с_объекта) %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question