私のアプリケーションでは、ユーザーは建物について説明します。ユーザーは、グループ化された選択を使用して、建物が存在する近隣を指定できる必要があります。モデルは次のようになります。
class Building
include Mongoid::Document
belongs_to :neighborhood
end
class Neighborhood
include Mongoid::Document
field :name, type: String, default: nil
field :borough, type: String, default: nil
field :city, type: String, default: nil
end
simple_form を使用して、建物が属する可能性のある近隣のリストを表すグループ化された選択を生成しようとしています。
= building_form.association :neighborhood, as: :grouped_select, collection: Neighborhood.where(city: city), group_method: :borough
理想的には、次のようなものを作成します。
Borough #1
Downtown
Uptown
Borough #2
Suburbs
...
ただし、次のエラーが表示されます。
undefined method `map' for "Borough #1":String
を呼び出しているように見えますがNeighborhood.borough.map
、String には関数がないため、map
エラーが発生します。これを修正するにはどうすればよいですか?