在Rails 3.0.9(Ruby 1.9.2,MySQL)我有一個方法,應該找到用戶使用兩個字段,類型(字符串)和標誌(布爾)。查詢的字符串部分工作正常,但不是布爾部分。Rails沒有找到價值使用!=
下面的代碼:
def find_users(type)
@private_users = User.where('type =? and flag != ?', org_type, true)
end
,試圖弄清楚發生了什麼事情,把這個代碼:
@users.each do |f|
puts "oh helllllllllllllllllllllllllllo #{f.user_name}"
puts "oh helllllllllllllllllllllllllllo #{f.flag}"
puts "oh helllllllllllllllllllllllllllo #{f.type}"
end
標誌字段爲空/空對於大多數的這些,而這些都是我正在嘗試拿起的那些。
如果我將表達式更改爲('type =? and flag = ?', type, true)
,它會正確找到其中1是標誌值的那些表達式。
我已經試過這些東西都無濟於事:
User.where('type =? and flag = ?', org_type, false)
User.where('type =? and flag = ?', org_type, "")
User.where('type =? and flag = ?', org_type, nil)
這可能爲某人一個簡單的問題,所以我希望一些人知道答案。謝謝!