我正在使用 best_in_place gem 内联编辑记录和 country_select呈现可供选择的国家/地区列表。当使用 best_in_place 编辑选择字段时,我这样做:
<%= best_in_place(@home, :country_name, :type => :select, :collection => [[1, "Spain"], [2, "Italy"]]) %>
现在我想获取 country_select 拥有的所有国家/地区的列表,并将其传递到集合参数中。 country_select gem 提供了一个简单的助手来呈现选择字段:
<%= country_select("home", "country_name") %>
我想替换 best_in_place 助手中的 :collection 参数以包含 country_select 提供的国家/地区列表。我知道 best_in_place 期望 [[key, value], [key, value],...] 输入到 :collection 中,但我不确定如何执行此操作。请指教。谢谢
最佳答案
只需执行以下操作即可:
<%= best_in_place @home, :country, type: :select, collection: (ActionView::Helpers::FormOptionsHelper::COUNTRIES.zip(ActionView::Helpers::FormOptionsHelper::COUNTRIES)) %>
关于ruby-on-rails-3 - 我如何将 country_select gem 与 best_in_place 编辑集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10243683/