groups_collection_select的Rails docs示例设置类似于我需要但我想使用2个选择。第一个将列出各大洲。然后,根据大陆选择,我想显示一个城市列表。
class Continent < ActiveRecord::Base
has_many :countries
# attribs: id, name
end
class Country < ActiveRecord::Base
belongs_to :continent
# attribs: id, name, continent_id
end
class City < ActiveRecord::Base
belongs_to :country
# attribs: id, name, country_id
end
我知道第一个选择将被写为:
<%= f.collection_select :continent_id, Continent.order(:name), :id, :name %>
第二个是给我带来问题:
<%= f.grouped_collection_select :city_id, Continent.order(:name), :countries, :name, :id, :name %>
国家桌的需要让我失望。有什么建议吗?