Created
April 19, 2012 22:54
-
-
Save meesterdude/2424738 to your computer and use it in GitHub Desktop.
trying to get @product_results to not contain products who are already in a given @category
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product < ActiveRecord::Base | |
has_and_belongs_to_many :product_groups | |
... | |
scope :in_categories, lambda {|ids| where(:category_id => ids) } | |
scope :visible, where(:visible => true) | |
scope :search, lambda {|kw| where( | |
['name LIKE :kw OR keywords LIKE :kw OR number LIKE :kw', :kw => "%#{kw}%"] | |
)} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProductGroup < ActiveRecord::Base | |
has_and_belongs_to_many :products | |
attr_accessible :name | |
validates :name, :presence => true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_remove | |
@product_group = ProductGroup.find(params[:id]) | |
@products = @product_group.products | |
@product_results = Product.search(params[:search]) | |
if params[:search].nil? || params[:search].empty? | |
@product_results = [] | |
else | |
@product_results = Product.search(params[:search]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment