Ruby on Rails-选择选项帮助器

| 有人可以帮助选择帮助者吗,因为我是Ruby On rails的新手。 我有一个如下的json对象,
@response = {\"status\" => \"200\", \"fruit\" => [ {
    \"id\" => 1,
    \"name\" => \"Apple\"
  }, {
    \"id\" => 2,
    \"name\" => \"Mango\"
  } ]
}
为此,我在助手中返回值\“ return @response [\'rateCard \'] \” 现在我想要从此帮助程序中生成视图文件中的此类代码,以便它具有如下选择框
<select name=\'fruit\'>
<option value=\"1\">apple</option>
<option value=\"2\" selected>mango</option>
</select>
请帮忙 实际上,我有一个助手“ Fruits_helper.rb”正在返回
def selFruit
    @resp = Fruit.getFruit # this will return @response object as mentioned above

    return @resp[\'fruit\']
end
================================================== =============================== 所以在我的fruit.html.erb文件中,我只有一小段代码,如下所示
<%= form_for(:AdminLogin) do |f| %>
<div>

<%= select_tag \"fruit\", options_for_select(selFruit.each{|fruit,key| [fruit[key]=>\'name\',fruit[key]=>\'id\']}) %>

<div>
<% end %>
================================================== ========================= 上面的代码给我o / p为
<select name=\"fruit\" id=\"fruit\">
<option value=\"id1nameApple\">id1nameApple</option>
<option value=\"id2nameMango\">id2nameMango</option>
</select>
我想要的结果是苹果     
已邀请:
        我的问题仅通过以下代码即可解决,希望它也能帮助其他RoR新生
<%= select_tag \"fruit\", options_for_select(selFruit.map{|fruit,key| [fruit[\'name\'], fruit[\'id\']]}) %>
    
        如果使用(并且应该使用)“ 6”构建器:
form.select(:fruit, @response[\"fruit\"].map { |f| [f[\"name\"], f[\"id\"]] })
    

要回复问题请先登录注册