我愛新的鐵路3!Rails 3:sql注入免費查詢
新的查詢語法是如此真棒:
users = User.where(:name => 'Bob', :last_name => 'Brown')
但是,當我們需要做的是這樣
SELECT * FROM Users WHERE Age >= const AND Money > const2
我們必須使用
users = User.where('Age >= ? and money > ?', const, const2)
這是不是很冷靜。下面的查詢是不是安全的,因爲SQL注入:
users = User.where('Age >= #{const} and money > #{const2}')
我喜歡的C#/ LINQ版本
var users = DB.Where(u => u.Age >= const && u.Money > const2);
有沒有辦法做這樣的事情,在Rails的?
謝謝!這就是我一直在尋找的。 – Alex 2010-08-03 07:01:10