This is working as is, but I'm pretty sure this is sloppy. Any tips on how to get all of this logic more rails-ish? I'm trying to implement will_paginate
with this, but first I need a cleaner way of selecting the right records.
#shoe table
-------------------------------------
size | brand | color | sold
-------------------------------------
8 somebrand black false
10 another brown true
-------------------------------------
def index
@shoes = Shoe.find_all_by_sold(false, :include => :assets)
#params[:size] = '8,9,10,11,11.5' || '8,9' || 'all'
if params[:size]
sizes = params[:size].split(',')
@shoes.reject! { |shoe| !sizes.include?(shoe.size.to_s) } unless sizes.include?('all')
end
# params[:color] = 'brown,black' || 'brown' || 'all'
if params[:color]
colors = params[:color].split(',')
@shoes.reject! { |shoe| !colors.include?(shoe.color.parameterize) } unless colors.include?('all')
end
# params[:brand] same as the others
if params[:brand]
brands = params[:brand].split(',')
@shoes.reject! { |shoe| !brands.include?(shoe.brand.parameterize) } unless brands.include?('all')
end
end