Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Product < ActiveRecord::Base
- has_many :build_rules
- # <tt>incompatible_products</tt> will return an array of products that
- # are not compatible with the current product.
- def incompatible_products
- products = []
- build_rules.each do |rule|
- products << rule.root.product if rule.root && rule.root != rule
- products << rule.children.map(&:product)
- end
- products.flatten
- end
- # <tt>incompatible_product?</tt> returns true or false depending on
- # whether the product passed is a compatible product or not.
- # ex.
- # <%= @product.incompatible_product?(@incompatible_product) %> # => true
- def incompatible_product?(product)
- incompatible_products.include?(product)
- end
- end
Add Comment
Please, Sign In to add comment