Skip to content

Commit

Permalink
Remove deprecated #search method (#1147)
Browse files Browse the repository at this point in the history
`#search` is deprecated in v2.1.1 and it scheduled to remove the
method in v2.3.
#975

But the method still exists in v2.3.2. So let's remove the method.

If we removed the method, users can remove the patch for `search`
(`ActiveRecord::Base.class_eval('remove_method :search'`).
  • Loading branch information
y-yagi authored Mar 10, 2022
1 parent a5feb0a commit 0fcf1b5
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 29 deletions.
26 changes: 0 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,32 +352,6 @@ construct much more complex search forms, such as the one on the
[demo app](http://ransack-demo.herokuapp.com/users/advanced_search)
(source code [here](https://github.com/activerecord-hackery/ransack_demo)).

### Ransack #search method

Ransack will try to make the class method `#search` available in your
models, but if `#search` has already been defined elsewhere, you can always use
the default `#ransack` class method. So the following are equivalent:

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

Users have reported issues of `#search` name conflicts with other gems, so
the `#search` method alias will be deprecated in the next major version of
Ransack (2.0). It's advisable to use the default `#ransack` instead.

For now, if Ransack's `#search` method conflicts with the name of another
method named `search` in your code or another gem, you may resolve it 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`
Expand Down
2 changes: 0 additions & 2 deletions lib/ransack/adapters/active_record/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module ActiveRecord
module Base

def self.extended(base)
alias :search :ransack unless base.respond_to? :search
base.class_eval do
class_attribute :_ransackers
class_attribute :_ransack_aliases
Expand All @@ -14,7 +13,6 @@ def self.extended(base)
end

def ransack(params = {}, options = {})
ActiveSupport::Deprecation.warn("#search is deprecated and will be removed in 2.3, please use #ransack instead") if __callee__ == :search
Search.new(self, params, options)
end

Expand Down
1 change: 0 additions & 1 deletion spec/ransack/adapters/active_record/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module ActiveRecord
subject { ::ActiveRecord::Base }

it { should respond_to :ransack }
it { should respond_to :search }

describe '#search' do
subject { Person.ransack }
Expand Down

0 comments on commit 0fcf1b5

Please sign in to comment.