在我的应用程序中,用户描述建筑物。用户应该能够使用分组选择指定建筑物所在的社区。模型看起来像:
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
函数,所以它会出错。我该如何解决?