这是按原样运作,但我很确定这是草率的。关于如何让所有这些逻辑更具轨道性的任何提示?我正试图用will_paginate
来实现,但首先我需要一种更清晰的方法来选择正确的记录。
#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
答案 0 :(得分:3)
答案 1 :(得分:2)
您可以在by_size
模型上为这些查询创建一些命名范围,例如by_colour
,by_brand
和Shoe
。然后你可以将它们以各种排列链接在一起。
这个Railscast应该会给你一个想法。