我在我的url中有以下參數。rails 4條件之間的多個範圍
考慮url../price=0-1000_2000-5001
我已經轉換了以上價格PARAMS作爲
pri = [["0", "1000"], ["2000", "5001"]] #This is not limited to only two
現在我怎麼可以查詢在軌以下
select * from product where price betweeen 0 and 1000 and price between 2000 and 5001 and so on
我發現下面的查詢中軌
Product.where(price: pri[0].first..pri[0].last)
但是我怎麼能找到多個範圍。
編輯-1
@posts = Post.where(價格:PRICE_RANGE)#此工作現在細
[1001..5000,10000..0]
這裏10000..0標明價格greater than 10000
但我查詢作爲
執行0SELECT * FROM職位,其中1001和5000的價格之間的價格10000和0
但查詢應該像之間的這種
SELECT * FROM職位,其中1001和5000的價格> 10000
之間價格checkbox1 = value 0-1000
checkbox2 = value 1001-5000
checkbox3 = value 5001-10000
checkbox4 = value 10001-15000
checkbox5 = value 15001-0(This indicates price > 15001)
您能否清楚一點嗎?檢查我的編輯 – overflow
@Seting,更新了我的答案,以幫助您瞭解更多條件。 – pdobb
那好,但它不是第二個。正如我之前所說,這不僅限於兩個,它是動態的。你可以檢查我更新的問題 – overflow