【发布时间】:2013-09-19 13:22:48
【问题描述】:
在我的应用程序中,用户描述建筑物。用户应该能够使用分组选择指定建筑物所在的社区。模型如下所示:
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,并且因为字符串没有map 函数,所以它会出错。我该如何解决这个问题?
【问题讨论】:
标签: ruby-on-rails forms simple-form