I think this is a simple question:
I have a Building model and each Building has_one city and each city belongs_to Buildings. I'd like to perform a search on the Building's city name (not the id) using Squeel.
Currently I have:
where{(zip =~ "%#{search}%") | (Building.all.map(&:city) =~ "%#{search}%")}
The searching through zip codes works fine since that is a direct attribute for the Building model. It's the second clause I am struggling with.
Right now, I get this error:
Cannot visit NilClass
How Can I make this work?