When making searches from polymorphic models it is necessary to specify the type of model you are searching.
Given two models
class House < ActiveRecord::Base
has_one :location, as: :locatable
class Location < ActiveRecord::Base
belongs_to :locatable, polymorphic: true
Normally (without polymorphic relationship) you would be able to search as per below:
However when this is searched you will get the following error
ActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association :locatable
In order to search for locations by house number when the relationship is polymorphic you have to specify the type of records you will be searching and construct your search as below:
_of_House_type_ added to the search key. This allows Ransack to correctly specify the table names in SQL join queries.