Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def results
- return @results unless @results.nil?
- # Strategy
- # First always, consider the weight range, right now we'll find where max_weight = :weight
- conditions = ['', {}]
- #conditions = ["weight_range_max = :weight", {:weight => self.weight}]
- # If they choose kids for intended use then just find shoes for kids and ignore gender
- #
- if self.intended_use == 'kids'
- conditions.first << ' category = :category'
- conditions.last[:category] = 'kids'
- else
- # If intended use is not kids, then we consider the gender
- conditions.first << ' category = :gender AND subcategory = :intended_use'
- conditions.last.merge!({ :gender => self.gender, :intended_use => self.intended_use })
- end
- # now cache and return the products
- @results = Product.find(:all, :conditions => conditions, :order => 'weight ASC, id ASC').inject([]) do |result_array, product|
- shoe_sizes = product.shoe_sizes.find(:all,
- :conditions => ["min_weight >= ? AND max_weight <= ?", self.min_weight, self.max_weight])
- result_array << {:product => product,
- :shoe_sizes => shoe_sizes } if shoe_sizes.count > 0
- result_array
- end
- @results
- end
- AND THE VIEW!!!
- <ul>
- <%- @snowshoe_chooser.results.each do |snowshoe| -%> <!--results hash unless results shoesizes symbol -->
- <li><%= link_to(h(snowshoe[:product].name), product_path(snowshoe[:product])) %> -
- size:<%= snowshoe.size %>
- </li>
- <%- end -%>
- </ul>
Add Comment
Please, Sign In to add comment