メンバーシップを使用して has_many に関連付けられている多くのカテゴリを持つ多くの製品があります。
カテゴリのドロップダウンで検索をフィルタリングしながら、誰でも製品を検索できる検索ボックスを作成しようとしています (したがって、関連するカテゴリの製品のみを取得できます)。
think_sphinx インデックスは Product モデルにあります。エラーは発生しませんが、ドロップダウンは検索に影響しません。
MODEL:
has_many :memberships,:dependent=> :destroy
has_many :categories, :through => :memberships
named_scope :published, :conditions => {:publish => 1}
define_index do
indexes product_name
indexes product_description
indexes publish
indexes memberships.product_id
indexes memberships.category_id
indexes categories.category_name
end
end
CONTROLLER:
@products = Product.search params[:search],:conditions=>{@product.memberships.category_id =>params[:category_product] },:page=> params[:page] || 1,:per_page =>4
VIEW:
form_tag search_path, :method =>:get do
text_field_tag :search, params[:search]
form_tag categories_path, :method => :get do
select_tag"category", options_from_collection_for_select (Category.find (:all, :group=>:id), :id, :category_name,params[:category_product])
end
submit_tag "search", :name => nil
end