fuzzily icon indicating copy to clipboard operation
fuzzily copied to clipboard

Rails 5: undefined method `fuzzily_searchable'

Open zachdaniel opened this issue 10 years ago • 8 comments

Trying to see if I can wire this up to a rails 5 api-only application, I've got the trigram model and migration set up correctly, but in my AR model when I include fuzzily_searchable :name (yes its actually called :name in my model) I get the undefined method fuzzily_searchable error.

zachdaniel avatar Oct 22 '15 15:10 zachdaniel

I've run into the same issue on a rails 4.2 project. All the fuzzily methods work correctly on the console and in my tests, but l get an undefined method error when they are called from the AR model.

dschlitt avatar Dec 03 '15 14:12 dschlitt

The issue is in /lib/fuzzily/searchable.rb, it has a case that includes the fuzzily_searchable methods, adding a 'when 5' fixes this problem:

    def self.included(by)
      case ActiveRecord::VERSION::MAJOR
      when 2 then by.extend Rails2ClassMethods
      when 3 then by.extend Rails3ClassMethods
      when 4 then by.extend Rails4ClassMethods
      when 5 then by.extend Rails4ClassMethods
      end
    end

samuelgiles avatar Jan 06 '16 21:01 samuelgiles

panna theriyalappa puriyira mathiru poduppa ...

mohanadevi avatar Jan 07 '16 10:01 mohanadevi

@samuelgiles do you have a fix PR?

sunapi386 avatar May 16 '16 02:05 sunapi386

Also having this issue, any progress on a solution?

DannySantos avatar Sep 28 '16 13:09 DannySantos

There are at least two PRs for this, but the repo hasn't received a commit in over a year (Aug 2015), so it seems dead (or just sleeping?).

At any rate, a workaround for this issue in Rails 5 applications is extending ActiveRecord::Base with the appropriate methods:

# config/initializers/fuzzily.rb:
ActiveRecord::Base.extend(Fuzzily::Searchable::Rails4ClassMethods)

speckins avatar Oct 27 '16 11:10 speckins

I'm pretty sure it's dead. Also, the current version does not work on 5.2 because of changes in callbacks between 5.0 and 5.2 (trigrams are no longer updated on name changes or creating new records).

I've been using a fork from cardillomarcelo up to now but it's disappeared (he probably gave up on this gem), but since I still need it, I created a fork that fixes this. It's provided only on a "works for me" basis (but feel free to send in PR's).

fjl82 avatar Jul 16 '18 14:07 fjl82

Oh no, I guess I have to fork. I'm upgrade to rails 5, one of my applications. Is there a lead fork, that is maintained now?

Tectract avatar Jan 07 '21 16:01 Tectract