How can you do a conditional where clause using Active Record

It is possible to chain where statements

residentials = Residential.where(:is_active => true)
residentials = residentials.where(:other_thing => true) if param_was_passed

This should work.

Make sure this is not the last line in a function call; repeat the residentials variable as the last line in that case. (As per @digger69 comment)

Leave a Comment

tech