Guest User

Untitled

a guest
Apr 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. def results
  2. return @results unless @results.nil?
  3. # Strategy
  4. # First always, consider the weight range, right now we'll find where max_weight = :weight
  5.  
  6. conditions = ['', {}]
  7. #conditions = ["weight_range_max = :weight", {:weight => self.weight}]
  8. # If they choose kids for intended use then just find shoes for kids and ignore gender
  9. #
  10. if self.intended_use == 'kids'
  11. conditions.first << ' category = :category'
  12. conditions.last[:category] = 'kids'
  13. else
  14. # If intended use is not kids, then we consider the gender
  15. conditions.first << ' category = :gender AND subcategory = :intended_use'
  16. conditions.last.merge!({ :gender => self.gender, :intended_use => self.intended_use })
  17. end
  18.  
  19. # now cache and return the products
  20. @results = Product.find(:all, :conditions => conditions, :order => 'weight ASC, id ASC').inject([]) do |result_array, product|
  21. shoe_sizes = product.shoe_sizes.find(:all,
  22. :conditions => ["min_weight >= ? AND max_weight <= ?", self.min_weight, self.max_weight])
  23. result_array << {:product => product,
  24. :shoe_sizes => shoe_sizes } if shoe_sizes.count > 0
  25. result_array
  26. end
  27. @results
  28. end
  29.  
  30.  
  31. AND THE VIEW!!!
  32.  
  33. <ul>
  34. <%- @snowshoe_chooser.results.each do |snowshoe| -%> <!--results hash unless results shoesizes symbol -->
  35. <li><%= link_to(h(snowshoe[:product].name), product_path(snowshoe[:product])) %> -
  36. size:<%= snowshoe.size %>
  37. </li>
  38.  
  39.  
  40. <%- end -%>
  41. </ul>
Add Comment
Please, Sign In to add comment