现在我在控制器中搜索逻辑:
def index
@title = "All cars"
#show manufacturers only with cars
@manufacturers = Manufacturer.select('*')
@manufacturers = @manufacturers.where('count_cars > ?', 0)
@cars = Car.select('*')
#manufacturer
@cars = @cars.where('manufacturer_id = ?', params[:filter_manufacturer]) if not params[:filter_manufacturer].blank?
#model
@models = Model.select('*')
@models = @models.where('manufacturer_id = ?', params[:filter_manufacturer]) if not params[:filter_manufacturer].blank? and not params[:filter_model].blank?
@models = @models.where('count_cars > ?', 0)
@cars = @cars.where('model_id = ?', params[:filter_model]) if not params[:filter_model].blank?
#years
@cars = @cars.where('year >= ?', params[:filter_year_from]) if not params[:filter_year_from].blank?
@cars = @cars.where('year <= ?', params[:filter_year_to]) if not params[:filter_year_to].blank?
#district
@cars = @cars.where('district_id = ?', params[:filter_district]) if not params[:filter_district].blank?
#body type
@cars = @cars.where('car_body_type_id = ?', params[:filter_body_type]) if not params[:filter_body_type].blank?
#fuel
@cars = @cars.where('car_fuel_id = ?', params[:filter_fuel]) if not params[:filter_fuel].blank?
#transmission
@cars = @cars.where('car_transmission_id = ?', params[:filter_transmission]) if not params[:filter_transmission].blank?
#wheel drive
@cars = @cars.where('car_drive_wheel_id = ?', params[:filter_drive_wheel]) if not params[:filter_drive_wheel].blank?
#doors
@cars = @cars.where('doors = ?', params[:filter_doors]) if not params[:filter_doors].blank?
#without damage
@cars = @cars.where('damage = ?', false) if params[:filter_damage]
#with customs
@cars = @cars.where('customs = ?', true) if params[:filter_customs]
#not crashed
@cars = @cars.where('crash = ?', false) if params[:filter_crash]
#price
@cars = @cars.where('price >= ?', params[:filter_price_from]) if not params[:filter_price_from].blank?
@cars = @cars.where('price <= ?', params[:filter_price_to]) if not params[:filter_price_to].blank?
@cars = @cars.paginate(:page => params[:page], :per_page => 20)
end
我必须将此逻辑移动到模型中吗?如果是,请帮助我进行标记。