Skip to content

Instantly share code, notes, and snippets.

Created November 18, 2009 22:18
Show Gist options
  • Save anonymous/238317 to your computer and use it in GitHub Desktop.
Save anonymous/238317 to your computer and use it in GitHub Desktop.
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|
result_array << {:product => product,
:shoe_sizes => product.shoe_sizes.find(:all,
:conditions => ["min_weight >= ? AND max_weight <= ?", self.min_weight, self.max_weight])}
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment