Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Does Ransack support the same polymorhpic belongs_to associations in searches as MetaSearch does? #152

gladgit opened this Issue Oct 26, 2012 · 1 comment


None yet
3 participants

gladgit commented Oct 26, 2012

I am migrating from the MetaSearch gem to the Ransack gem for an upgrade to Rails 3.1 and I am having problems with my searches on polymorphic associations. The existing MetaSearch syntax isn't working for Ransack, but I couldn't find any documentation mentioning any syntax changes. Or whether this feature is supported in Ransack.

For example, from the MetaSearch github page, given the following classes:

class Article < ActiveRecord::Base
  has_many :comments, :as => :commentable

class Post < ActiveRecord::Base
  has_many :comments, :as => :commentable

class Comment < ActiveRecord::Base
  belongs_to :commentable, :polymorphic => true
  validates_presence_of :body

you can create a search field in your form like this:

<%= f.text_field :commentable_article_type_body_contains %>

I am using this type of syntax, which works perfectly in MetaSearch, but with Ransack my application is throwing an exception when the query parameter contains this field. The exception is:

ActiveRecord::EagerLoadPolymorphicError (Can not eagerly load the polymorphic association :ownable)

How do I search on polymorphic associations in Ransack?

wkoffel commented Nov 23, 2015

May be addressed here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment