如何将country_select gem与best_in_place编辑整合 [英] How can i integrate country_select gem with best_in_place editing
问题描述
我正在使用 best_in_place gem编辑内联记录和
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"]]) %>
现在,我想获取country_select拥有的所有国家/地区的列表,并将其传递给collection参数. country_select gem提供了一个简单的助手来呈现选择字段:
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") %>
我想替换best_in_place帮助器中的:collection参数,以包括country_select提供的国家/地区列表.我知道best_in_place期望将[[key,value],[key,value],...]输入到:collection中,但是我不确定如何做到这一点.请指教.谢谢
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)) %>
这篇关于如何将country_select gem与best_in_place编辑整合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!