I am having many products with many categories which are associated with has_many using memberships.
I am trying to create a search box where any one can search products while also filter their search with a category dropdown (so only products with relevant categories can be retrieved).
The thinking_sphinx index is in Product model I don't get any errors but dropdown does not effect the search.
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