Каков наилучший способ группировки параметров при использовании MongoDB?Как сгенерировать optgroup в рельсах с Mongoid?
Я использую Mongoid, когда я попробовал этот подход:
<%= field.select :resource_id,
grouped_options_for_select(Resource.all.group_by{"resource_type_id"}.map {|k,m|
[m.first.title, m.first.id] }),:prompt => true %>
Это дает мне следующую ошибку:
undefined method `map' for "5177e6a5359f105f89000001":Moped::BSON::ObjectId
Пока я ищу:
<select>
<optgroup label="RT1"> <!-- RT1 is the name of resource type -->
<option value="5177e6a5359f105f89000001">Res1</option>
</optgroup>
</select>
Также , в консоли выход для Resource.all.group_by{"resource_type_id"}
:
=> {"resource_type"=>[#<Resource _id: 5177e6a5359f105f89000001,
created_at: 2013-04-24 14:05:25 UTC, updated_at: 2013-04-24 14:54:14 UTC,
title: {"en"=>"Res1"}, slug: {"en"=>"res1"}, content:
{"en"=>"This is the content for First Resource."},
excerpt: {"en"=>"This is the content for First Resource."}, published: true,
resource_type_id: "5177e3ba359f10d345000004">]}
В то время как ожидаемый результат
=> {"RT1"=>[#<Resource _id: 5177e6a5359f105f89000001,
created_at: 2013-04-24 14:05:25 UTC, updated_at: 2013-04-24 14:54:14 UTC,
title: {"en"=>"Res1"}, slug: {"en"=>"res1"}, content:
{"en"=>"This is the content for First Resource."},
excerpt: {"en"=>"This is the content for First Resource."}, published: true,
resource_type_id: "5177e3ba359f10d345000004">]}