【发布时间】: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
我怎么能用这样的东西:
@comments = @company.comments.where(:approved => true).or(:ip => request.remote_ip).all
我是否应该为此安装任何特定的 gem?
我使用的是 rails 3.0.4 和 mysql2。
谢谢。
【问题讨论】:
标签: ruby-on-rails-3 conditional-operator
请参阅“条件”部分 in the documentation,其中解释了在条件中使用多个参数。您的查询将被写入:
@comments = @company.comments.where('approved = ? OR ip = ?', true, request.remote_ip).all
【讨论】: