Guest User

Untitled

a guest
Jul 22nd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. class Product < ActiveRecord::Base
  2.  
  3. has_many :build_rules
  4.  
  5. # <tt>incompatible_products</tt> will return an array of products that
  6. # are not compatible with the current product.
  7. def incompatible_products
  8. products = []
  9.  
  10. build_rules.each do |rule|
  11. products << rule.root.product if rule.root && rule.root != rule
  12. products << rule.children.map(&:product)
  13. end
  14.  
  15. products.flatten
  16. end
  17.  
  18. # <tt>incompatible_product?</tt> returns true or false depending on
  19. # whether the product passed is a compatible product or not.
  20. # ex.
  21. # <%= @product.incompatible_product?(@incompatible_product) %> # => true
  22. def incompatible_product?(product)
  23. incompatible_products.include?(product)
  24. end
  25.  
  26. end
Add Comment
Please, Sign In to add comment