ransack icon indicating copy to clipboard operation
ransack copied to clipboard

Polymorphic Associations and searching parent of parent

Open ZASMan opened this issue 8 years ago • 1 comments

Here is a small gist of my model setup.

I'm using ransack to search the index page of the EmailLogs model and search by UserName. The Email Logs can belong to either a Notebook or a NotebookArticle, however, and the user is a direct parent to the notebook, while the notebookarticle's parent is the user whose parent is in turn the user.

I've looked at the documentation for polymorphic searches and can't quite get it to work. What I'm endeavoring to accomplish is something like this:

<%= f.search_field :email_loggable_of_Email_log_user_name_cont, :class => 'form-control', :id => 'q_traveler_last_name_or_user_first_name_cont', :placeholder => "Last, First" %>

However this doesn't seem to be the case, I get an error of uninitialized constant EmailLog::EmailLoggable. Does anyone have any tips?

ZASMan avatar Feb 01 '18 16:02 ZASMan

I have also the class structure like this

module Custom
  module Directory
    class File
      has_one :card, as: :card, class_name: "Custom::Card"
    end
  end
end


module Custom
  class card
    belongs_to :card, polymorphic: true
  end
end

and I am adding the filter in active admin like card_of_Custom::Directory::File_type_card_id according to the documentation of https://activerecord-hackery.github.io/ransack/going-further/polymorphic-search/

but getting the error like :card_of_Custom is not a class/module.

ActiveAdmin Version is 2.12.0

Please help.

amit-dhoundiyal avatar Feb 10 '25 07:02 amit-dhoundiyal