Skip to content

Instantly share code, notes, and snippets.

@BaylorRae
Created September 1, 2012 12:46
Show Gist options
  • Save BaylorRae/3572342 to your computer and use it in GitHub Desktop.
Save BaylorRae/3572342 to your computer and use it in GitHub Desktop.
# product.rb
class Product < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations
end
# category.rb
class Category < ActiveRecord::Base
has_many :categorizations
has_many :products, :through => :categorizations
end
# categorization.rb
class Categorization < ActiveRecord::Base
belongs_to :category
belongs_to :product
end
<%= search_form_for @query do |f| %>
<%= f.label :categories_id_eq, "Category" %>
<%= f.collection_select :categories_id_eq, Category.order(:title), :id, :title %>
<%= f.submit "Filter Products" %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment