开发者

How to use OR operator in find method?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜