textacular icon indicating copy to clipboard operation
textacular copied to clipboard

The .search method conflicts with methods in other gems like Ransack

Open NielsKSchjoedt opened this issue 9 years ago • 3 comments

I suggest a rename og the .search method. The name is too generic and conflicts with other gems like https://github.com/activerecord-hackery/ransack

NielsKSchjoedt avatar May 12 '16 08:05 NielsKSchjoedt

Ransack doesn't alias the search method if it is already defined and you can just use the original ransack method in that case. But actually we should could do something similar.

gregmolnar avatar May 16 '16 16:05 gregmolnar

I get the same problem when define such enum:

class AdvertiserChannelMapping < ApplicationRecord
  enum mkt_channel: {
    organic:        "Organic",
    emai:           "Email",
    facebook:       "Facebook",
    other_paid:     "Other Paid",
    test:           "Test",
    search:         "Search",
    mobile_display: "Mobile Display"
  }
end

gems/activerecord-5.0.6/lib/active_record/enum.rb:228:in `raise_conflict_error': You tried to define an enum named "mkt_channel" on the model "AdvertiserChannelMapping", but this will generate a class method "search", which is already defined by Active Record. (ArgumentError)

I solved the issue by next dirty hack config/initializers/textacular.rb:

module Textacular
  undef :search
end

akrisanov avatar Sep 26 '17 23:09 akrisanov

I think we can make this (adding methods to model) configurable and also introduce non-invasive wrapper like Textacular(MyModel).basic_search('ABC'). WDYT?

simi avatar Mar 01 '20 19:03 simi