His*_*alv 3 inline-editing ruby-on-rails-3 best-in-place
我使用best_in_place gem来编辑内联和country_select记录,以呈现可供选择的国家列表.使用best_in_place编辑选择字段时,我这样做:
<%= best_in_place(@home, :country_name, :type => :select, :collection => [[1, "Spain"], [2, "Italy"]]) %>
Run Code Online (Sandbox Code Playgroud)
现在,我想获得country_select所有国家/地区的列表,并将其传递到collection参数中.country_select gem提供了一个简单的帮助器来呈现select字段:
<%= country_select("home", "country_name") %>
Run Code Online (Sandbox Code Playgroud)
我想替换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)) %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1136 次 |
| 最近记录: |