Skip to content

Commit

Permalink
Update README re #search method name conflicts.
Browse files Browse the repository at this point in the history
TODO: allow opting-out of `alias :search :ransack`
in the Ransack config/initializer file.

[skip ci]
jonatack committed Nov 9, 2014
1 parent f858dd6 commit 5c7bb9e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -229,13 +229,24 @@ construct much more complex search forms, such as the one on the

Ransack will try to to make `#search` available in your models, but in the case
that `#search` has already been defined, you can use `#ransack` instead. For
example the following would be equivalent:
example, the following would be equivalent:

```ruby
Article.search(params[:q])
Article.ransack(params[:q])
```

If Ransack's `#search` method conflicts with the name of another method named
`search` in your code or another gem, it may be resolved either by patching
the `extended` class_method in `Ransack::Adapters::ActiveRecord::Base` to
remove the line `alias :search :ransack unless base.respond_to? :search`, or by
placing the following line in your Ransack initializer file at
`config/initializers/ransack.rb`:

```ruby
Ransack::Adapters::ActiveRecord::Base.class_eval('remove_method :search')
```

### Associations

You can easily use Ransack to search for objects in `has_many` and `belongs_to`

1 comment on commit 5c7bb9e

@jonatack
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addresses #369.

TODO: allow users to opt-out of alias :search :ransack via setting a different value the Ransack config/initializer file.

Please sign in to comment.