1
是否有使用对象像(错误地)Rails的查询,其中属性等于FOO或酒吧
Model.where(attribute: "foo" || "bar")
用于链接特别有用的,例如,以写
Model.where("attribute = ? OR attribute = ?", "foo", "bar")
的方式:
Model.where(attr_one: "blaz").where("attr_two = ? OR attr_two = ?", "foo", "bar")
变成(不正确)
Model.where(attr_one: "blaz", attr_two: "foo" || "bar")
而且头脑很开心。
用的问题的这里的意图是''foo“||在ActiveRecord可以做任何事情之前,“bar”评估为“foo”。 – tadman 2014-09-04 20:51:34