你可以这样做:
conditions = {}
conditions[:game_genre] = @genre if params[:genre].present?
withs = {}
withs[:distibuter_id] = @distributer_id if params[:distibuter].present?
withs[:price_in_gbp] = @price if params[:price].present?
# ...
DistributerGame.search :conditions => conditions, :with => withs
坚持你params
的不同页面:
#in your view:
filter_params = {}
filter_params[:game_genre] = params[:genre] if params[:genre].present?
filter_params[:distibuter] = params[:distibuter] if params[:distibuter].present?
filter_params[:price_in_gbp] = params[:price] if params[:price].present?
@distributers.each do |d|
filters_params[:distibuter] = d.id
link_to d.name, filter_params # you may have to merge this with your resource_path
@genres.each do |g|
filter_params[:genre] = g.id
link_to g.name, filter_params