I am using the best_in_place gem to edit records inline and country_select to render a list of countries to select from. When using best_in_place to edit a select field i do this:
<%= best_in_place(@home, :country_name, :type => :select, :collection => [[1, "Spain"], [2, "Italy"]]) %>
Now i like to get a list of all the countries that country_select has and pass that into the collection parameter. The country_select gem provides a simple helper to render the select field:
<%= country_select("home", "country_name") %>
I would like to replace the :collection parameter in best_in_place helper to include the list of countries provided by country_select. I know that best_in_place expects the [[key, value], [key, value],...] input into :collection, but i am not sure how to do this. Please advise. Thanks
Just do the following and it will work:
<%= best_in_place @home, :country, type: :select, collection: (ActionView::Helpers::FormOptionsHelper::COUNTRIES.zip(ActionView::Helpers::FormOptionsHelper::COUNTRIES)) %>
If you are using rails 4 a few years later , this does the trick:
<%= best_in_place @cart.order, :country_name, type: :select, :collection => ActionView::Helpers::FormOptionsHelper::COUNTRIES%>
来源:https://stackoverflow.com/questions/10243683/how-can-i-integrate-country-select-gem-with-best-in-place-editing