mrkamel/search_cop

Error when using with non-standard pluralization in class name

Closed this issue · 2 comments

My class for windows devices is named Device::Windows, rather than Device::Window... becuase Window isn't the OS name. Device::Mac works great with search_cop though :)

class Device::Windows < ApplicationRecord
  include SearchCop

  search_scope :search do
    attributes :serial_number, :hostname
  end
end
bc-windows:development [44] pry(main)> Device::Windows.search('kuzmik')
NameError: uninitialized constant Device::Window
from /Users/kuzmik/.rbenv/versions/2.6.5/gemsets/widows/gems/activesupport-5.2.4/lib/active_support/inflector/methods.rb:285:in `const_get'
windows:development [45] pry(main)>

I tried setting up inflections in the rails initializer, but it didn't seem to do the trick.

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.plural 'Device::Windows', 'Device::Windows'
  inflect.singular 'Device::Windows', 'Device::Windows'
end

I assume it's something silly I have misconfigured somewhere, but any help you can provide would be appreciated. I'd love to drop ransack and use search_cop instead!

hi, please try to add inflections for "device/windows".

that did the trick! thank you much.