Skip to content

Commit

Permalink
Merge pull request #392 from platanus/include-method-model-to-readme
Browse files Browse the repository at this point in the history
feat(select2-search): include documentation for other table search or…
  • Loading branch information
ldlsegovia authored Mar 3, 2022
2 parents 51a0e4b + 330dc24 commit 7508859
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion docs/select2_search.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ If you want to use url helpers, use a `proc` like on the example
order_by: 'description_asc'
```

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:

```ruby
filter :posts_user_id, as: :search_select_filter, url: proc { admin_users_path },
fields: [:name, :email], display_name: 'email', minimum_input_length: 2,
order_by: 'description_asc', method_model: User
```

### Options

* `category_id`: Notice we're using the relation field name, not the relation itself, so you can't use `f.input :category`.
Expand All @@ -35,4 +43,5 @@ If you want to use url helpers, use a `proc` like on the example
* `class`: **(optional)** You can pass extra classes for your field.
* `width`: **(optional)** You can set the select input width (px or %).
* `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.
* `predicate`: **(optional)** You can change the default [ransack predicate](https://github.com/activerecord-hackery/ransack#search-matchers). It **defaults to** `contains`
* `predicate`: **(optional)** You can change the default [ransack predicate](https://github.com/activerecord-hackery/ransack#search-matchers). It **defaults to** `contains`.
* `method_model`: **(optional)** Use in case you need to search or filter an attribute of another table.

0 comments on commit 7508859

Please sign in to comment.