在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)
这可能为某人一个简单的问题,所以我希望一些人知道答案。谢谢!