我通过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