Skip to content

Commit 7508859

Browse files
authored
Merge pull request #392 from platanus/include-method-model-to-readme
feat(select2-search): include documentation for other table search or…
2 parents 51a0e4b + 330dc24 commit 7508859

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docs/select2_search.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ If you want to use url helpers, use a `proc` like on the example
2323
order_by: 'description_asc'
2424
```
2525

26+
In case you need to filter with an attribute of another table you need to include the `method_model` option. In the classic User has many Post's and Post has many Comment's example, in the Comment index you could add this filter:
27+
28+
```ruby
29+
filter :posts_user_id, as: :search_select_filter, url: proc { admin_users_path },
30+
fields: [:name, :email], display_name: 'email', minimum_input_length: 2,
31+
order_by: 'description_asc', method_model: User
32+
```
33+
2634
### Options
2735

2836
* `category_id`: Notice we're using the relation field name, not the relation itself, so you can't use `f.input :category`.
@@ -35,4 +43,5 @@ If you want to use url helpers, use a `proc` like on the example
3543
* `class`: **(optional)** You can pass extra classes for your field.
3644
* `width`: **(optional)** You can set the select input width (px or %).
3745
* `order_by`: **(optional)** Order (sort) results by a specific attribute, suffixed with `_desc` or `_asc`. Eg: `description_desc`. By **default** is used the first field in descending direction.
38-
* `predicate`: **(optional)** You can change the default [ransack predicate](https://github.com/activerecord-hackery/ransack#search-matchers). It **defaults to** `contains`
46+
* `predicate`: **(optional)** You can change the default [ransack predicate](https://github.com/activerecord-hackery/ransack#search-matchers). It **defaults to** `contains`.
47+
* `method_model`: **(optional)** Use in case you need to search or filter an attribute of another table.

0 commit comments

Comments
 (0)