form_tagを使用して検索フォームにいくつかの動的ドロップダウン選択メニューを設定しようとしています。Rails4 Dynamic Selectドロップダウン
class Count < ActiveRecord::Base
belongs_to :host
end
class Host < ActiveRecord::Base
belongs_to :site
has_many :counts
end
class Site < ActiveRecord::Base
belongs_to :state
has_many :hosts
end
class State < ActiveRecord::Base
has_many :sites
end
ビュー:多くのカウントを持っているホストのHAS_MANY
<%= form_tag(counts_path, :method => "get", id: "search-form") do %>
<%= select_tag "state_id", options_from_collection_for_select(State.all.order(:name), :id, :name) %>
<%= select_tag "site_id", options_from_collection_for_select(Site.all.order(:name), :id, :name) %>
<% end %>
A状態にhas_manyサイト私が希望することはRailcasts #88
モデルで発見例と同様の機能です。または反対に、カウントはbelongs_toホストに属していますbelongs_to状態に属するサイト
Stateドロップダウンからホストを介して関連付けられた状態に基づいてサイトをグループ化したいと考えています。
私はこのネストされた関連付けに苦労しており、grouped_collection_selectの構築方法を理解できていないようです。
私は明らかな何かを見落としていることを知っています!いくつかのポインタを使用することができます...