Skip to content

Commit 5a2d2b2

Browse files
authored
Merge pull request #8 from excid3/patch-2
Add controller example
2 parents eb473d4 + f0db4bd commit 5a2d2b2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,23 @@ Typesense.configuration = {
229229
}
230230
```
231231

232+
### Pagination & Search in a controller with Pagy
233+
234+
```ruby
235+
class ProductsController < ApplicationController
236+
def index
237+
# If `params[:q]` is blank, Typesense will automatically use "*" to return all documents
238+
@pagy, @products = Product.search(params[:q], "name,description")
239+
end
240+
end
241+
```
242+
243+
```erb
244+
<h1>Search results for <%= params[:q] %></h1>
245+
<%= render @products %>
246+
<%== pagy_nav(@pagy) if @pagy.pages > 1 %>
247+
```
248+
232249
## Testing
233250

234251
To run the test suite:

0 commit comments

Comments
 (0)