문제

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