Search code examples
ruby-on-rails-3arel

Rails3 Arel Building the Where Clause


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?


Solution

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

    rec.all