Reputation: 2914
I am not receiving any returned results when I do a search query.
def index
@users = User.where(zip_code: locations.map(&:zipcode))
@users = User.search(params[:search].gsub(/\s+/, ' | '))
Though if I do what's below it returns the results:
@users = User.where(zip_code: locations.map(&:zipcode))
else
@users = User.search(params[:search].gsub(/\s+/, ' | '))
Why is it that I have to add else? Shouldn't I be able to run both? I want to run both of them at the same time to get the expected return results.
In other parts of my app I can have it look like the original code above and it works as expected. But in this controller it doesn't.
Upvotes: 0
Views: 50
Reputation: 1025
I would need to see more of your code but i guess it is related to your #search
method being a method. :p
To chain methods like:
User.where(zip_code: locations.map(&:zipcode)).search(params[:search].gsub(/\s+/, ' | '))
you will need the search method to be an scope. =)
Upvotes: 1