【问题标题】:How to use OR operator in find method?如何在查找方法中使用 OR 运算符?
【发布时间】:2011-03-04 18:08:56
【问题描述】:

我怎么能用这样的东西:

@comments = @company.comments.where(:approved => true).or(:ip => request.remote_ip).all

我是否应该为此安装任何特定的 gem?

我使用的是 rails 3.0.4 和 mysql2。

谢谢。

【问题讨论】:

    标签: ruby-on-rails-3 conditional-operator


    【解决方案1】:

    请参阅“条件”部分 in the documentation,其中解释了在条件中使用多个参数。您的查询将被写入:

    @comments = @company.comments.where('approved = ? OR ip = ?', true, request.remote_ip).all
    

    【讨论】:

      猜你喜欢
      • 2018-11-11
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2022-01-02
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多