You can do this:
conditions = {}
conditions.merge!(:procedure_id => params[:procedure_id]) if params[:procedure_id]
conditions.merge!(:location_id.in => params[:location_ids]) if params[:location_ids]
...
@blood_banks = BloodBank.where(conditions)
EDIT:
Regarding your last code, since you have no logic here (common idea for all values), you can use case
:
condition = case params[:fees]
when "300"
{ '$lte' => 300 }
when "500"
{ '$gte' => 300, '$lte' => 500 }
when "1000"
{ '$gte' => 500, '$lte' => 1000 }
when "1001"
{ '$gte' => 1001 }
else
nil
end
if condition
@doctor_clinic = DoctorClinic.where( :consultation_fees => condition).map(&:doctor_id)
@doctors = Doctor.where({ :id.in => @doctor_clinic })
end