Reputation: 9492
I have a database of 'events' with a bunch of attributes. How can I allow my users to search for 'events'. I have seen the tutorial on doing text searches, but I'm looking for more ON/OFF searches.
Each event has a time, location (coordinates), and a few other selectors. I would like a user to be able to search based on time (min,max) and/or location (closest to their input coordinates) and select from selectors.
How can I do this? Any specific tutorials that I should look at. I couldn't find anything near by nears. Thanks
Must include multiple attributes and boolean math (is the search location within 5km of an 'event' location.
Thanks
Upvotes: 0
Views: 298
Reputation: 2538
Try scopes. Create a scope for each searchable attribute in a model.
For example time attribute:
scope :time_search, ->(min, max) { where("time_column > ? AND time_column < ?", min, max) }
And then from controller: Model.time_search(params[:min], params[:max])
.
You can also chain scopes, like this: Model.scope_1(param).scope_2(param)
, which will filter records based on criteria from those 2 scopes.
Upvotes: 1