Closed ate-it closed 3 years ago
Hi @JackWetson ,
I would think that with the way you have set up the faction_search scope, it would always return an array. You can try to play with the scope in console to see if it returns what you are after. I don't fully understand what your scope it trying to do, but I it seems like you want to search for records in Player where the field faction
matches the query? What is the num_or_conds
part? It also seems like you have to do a lot of sanitation on the query - maybe you could refactor that out in a function of its own or do it in the form?
After the cleanup of the query, I would think a basic scope : faction_search, ->(factions) { where('players.factions = ?', factions) }
would do it. If factions is an array, it will return all matches.
Andreas
@alydersen you are totally correct, i'd massively over complicated this, I've stripped this right back to the below and its working as expected, thank you
scope :faction_search, lambda { |faction|
return nil if faction.blank?
where('faction LIKE ?', faction)
}
Perfect - glad it worked out :-)
So I'm trying to implement my first search query and I seem to be having issues with the data coming back as an array, but I cannot quite see how this is happening, any pointers would be appreciated!
filterrific (5.2.1) rails (5.2.4.1) ruby (2.6.5)
Model
Controller