I'm trying to build the where clause using AREL but this does not execute the query:

 rec = self.where('color' => color_passed)
 rec = rec.where('make' => make_passed) if make_passed.present?
 rec = rec.where('year' => year_passed) if year_passed.present?

How can I correctly append the where conditions based on some conditions?

有帮助吗?

解决方案

What do you mean not execute? where only return a Relation object, you have to call all to get the result:

rec.all
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top