How to specify multiple values in where with AR query interface in rails3

前端 未结 7 1016
时光说笑
时光说笑 2020-12-28 13:31

Per section 2.2 of rails guide on Active Record query interface here:

which seems to indicate that I can pass a string specifying the condition(s), then an array of

7条回答
  •  生来不讨喜
    2020-12-28 14:05

    Sounds like you're doing something like this:

    Model.where("attribute = ? OR attribute2 = ?", [value, value])
    

    Whereas you need to do this:

    # notice the lack of an array as the last argument
    Model.where("attribute = ? OR attribute2 = ?", value, value)
    

    Have a look at http://guides.rubyonrails.org/active_record_querying.html#array-conditions for more details on how this works.

提交回复
热议问题