我通過get發送數據,我需要將它放入一個int數組中以用於查找。 這裏是我的代碼:ruby rails將params轉換爲int數組
@found = Array.new
params['candidate'].each do |c|
@found << c.to_i
end
我的URL看起來像這樣
http://localhost:3000/export/candidate?candidate[]=3&candidate[]=4&commit=Export
如果它使我使用它這方面的任何差別發現
@candidate = Candidate.find(:all, :conditions => ["candidates.id IN ?", @found])
但是目前我們沒有把它放在一個真正的陣列,因爲我得到這個錯誤
Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '4)' at line 1: SELECT * FROM `candidates` WHERE (candidates.id IN 4,2)
支架在陣列周圍缺失
謝謝,早上好!
亞歷
感謝您的幫助! 這是什麼意思&:? – Alex 2010-07-18 09:12:09
這是一種簡單的方法,將一個只調用給定方法的塊傳遞給塊中的參數。有一個很好的解釋http://pragdave.pragprog.com/pragdave/2005/11/symbolto_proc.html – Gareth 2010-07-18 09:14:27
謝謝,ruby是如此酷的語言! – Alex 2010-07-18 09:40:40