开发者

How to use OR operator in find method?

开发者 https://www.devze.com 2023-02-15 08:33 出处:网络
how could I use something like this: 开发者_如何学编程 @comments = @company.comments.where(:approved => true).or(:ip => request.remote_ip).all

how could I use something like this:

开发者_如何学编程
@comments = @company.comments.where(:approved => true).or(:ip => request.remote_ip).all

Should I have to install any specific gem for doing this?

I using rails 3.0.4 and mysql2.

Thanks.


See the "Conditions" section in the documentation, where it explains using multiple parameters in the conditions. Your query would be written:

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

精彩评论

暂无评论...
验证码 换一张
取 消