Ransack: Searching polymorphic relation want to use of "or" and "and"

Created on 7 Apr 2016  路  4Comments  路  Source: activerecord-hackery/ransack

I try Searching polymorphic relation with "or" and "and".

models

class Image < ActiveRecord::Base
  belongs_to :parent, polymorphic: true
end

class Item < ActiveRecord::Base
  has_many :images, as: :parent
end

class Book < ActiveRecord::Base
  has_many :images, as: :parent
end

view

app/views/images/index.html.slim

= search_form_for [:admin, @search] do |f|
  = f.text_field :parent_of_Item_type_name_start_or_parent_of_Book_type_name_start
  = f.submit

error

But don't work :cry:

undefined method `parent_of_Item_type_name_start_or_parent_of_Book_type_name_start' for Ransack::Search>:Ransack::Search

Can Searching polymorphic relation use "or" and "and"?

My English isn't well, sorry :bow:

All 4 comments

See the excellent answer by @avit in #646 for more complex query control. Let us know how it works for you!

If that does not work, please provide a gist based on this template to reproduce and I'll have a look.

Thank you for teaching me, jonatack!
= f.text_field :parent_of_Item_type_name_or_parent_of_Book_type_name_start
It's work.

Thanks for the feedback! I'm sorry I didn't see the extra _start in the middle of your query right away.

Was this page helpful?
0 / 5 - 0 ratings