Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryanckulp/customer_autocomplete_demo
query a table of records in style
https://github.com/ryanckulp/customer_autocomplete_demo
Last synced: 27 days ago
JSON representation
query a table of records in style
- Host: GitHub
- URL: https://github.com/ryanckulp/customer_autocomplete_demo
- Owner: ryanckulp
- Created: 2019-06-25T21:59:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-19T13:30:56.000Z (almost 2 years ago)
- Last Synced: 2024-10-28T10:12:32.269Z (2 months ago)
- Language: Ruby
- Size: 681 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 33
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Customer Autocomplete Demo
query a database table of Customers by first name, email, etc.
### installation
1. git clone `https://github.com/ryanckulp/customer_autocomplete_demo.git`
1. bundle (might need to install ruby version via `rbenv install 2.6.1` first)
3. `rails db:create && rails db:migrate && rails db:seed`
4. `rails s` then visit localhost:3000 and try it### how it works
1. `keyup` JS listener on the input field pings search via `/customer_searches/new?query=X`
2. controller delegates search query to `Customer.search()`
3. `Customer.search()` performs case-insensitive search for "first_name" attribute only### extensions
can include email address, last name, etc attributes in search parameters via modifications like...
```ruby
def self.search(params)
results = where("first_name ILIKE '%#{params[:query]}%'")
results += where("last_name ILIKE '%#{params[:query]}%'")
results += where("email ILIKE '%#{params[:query]}%'")results.uniq.map { |c| { id: c.id, full_name: c.full_name } }
end
```