How can i integrate country_select gem with best_in_place editing

依然范特西╮ 提交于 2019-12-06 08:18:51

问题


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


回答1:


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)) %>



回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!