2

grouped_collection_select の Rails ドキュメントの例は、必要なものと同様に設定されていますが、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 %>

2番目のものは私に問題を与えています:

<%= f.grouped_collection_select :city_id, Continent.order(:name), :countries, :name, :id, :name %>

カントリーテーブルの必要性は私をうんざりさせています。助言がありますか?

4

0 に答える 0