Skip to content

Commit

Permalink
Add README example of calling the collection block
Browse files Browse the repository at this point in the history
  • Loading branch information
spohlenz committed Jul 30, 2017
1 parent 5272254 commit 4dfab72
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,24 @@ Trestle.resource(:articles) do
end
```

The search block accepts one or two parameters; the first is the string value of the search query. The second, optional parameter is the complete `params` hash.
The search block accepts one or two parameters; the first is the string value of the search query. The second, optional parameter is the full `params` hash.

The search block will be called instead of the default (or custom) `collection` block when the `q` query parameter is present (i.e. when a search query has been entered). It must return a chainable scope.

The original collection block can be called to avoid redefining scopes. For example:

```ruby
Trestle.resource(:articles) do
collection do
Article.order(created_at: :desc).includes(:author)
end

search do |q|
collection.where("title ILIKE ?", "%#{q}%")
end
end
```


## License

Expand Down

0 comments on commit 4dfab72

Please sign in to comment.