Is it possible to add OR statements to a scope argument in a rails model something like

scope :west_coast, where(:st => "CA" || "WA" || "OR")
有帮助吗?

解决方案

The question is really how to make an sql WHERE ... IN statement using activerecord:

scope :west_coast, where(st: %w(CA WA OR))

其他提示

Try this:

scope :west_coast, where(['st = ? or st = ? or st = ?'], "CA", "WA", "OR")
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top