Kleber S.
Kleber S.

Reputation: 8240

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.

Upvotes: 2

Views: 419

Answers (1)

Michelle Tilley
Michelle Tilley

Reputation: 159115

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

Upvotes: 2

Related Questions