最佳答案
我知道为 where
ActiveRecord 方法提供参数有3种主要的表示法:
为 where
方法指定 and
很简单:
# Pure String notation
Person.where("name = 'Neil' AND age = 27")
# Array notation
Person.where(["name = ? AND age = ?", 'Neil', 27])
# Hash notation
Person.where({name: "Neil", age: 27})
为这个相同的 where
方法指定 or
就是为散列语法做难题。这可能吗?
# Pure String notation
Person.where("name = 'Neil' OR age = 27")
# Array notation
Person.where(["name = ? OR age = ?", 'Neil', 27])
# Hash notation DOESN'T WORK
Person.where({name: "Neil" OR age: 27})