Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

693
Views
Multiple polymorphic association search using Ransack, is it possible?

I have the class Invoice that belongs_to Invoiceable, a polymorphic class. The Invoiceable of Invoice can either be Subscription or Purchase.

I need to be able to search by the status of an Invoice's Subscription or Purchase.

I'm trying the following to no success:

<%= f.check_box :invoiceable_of_Subscription_or_Purchase_type_status_in, { multiple: true }, type[1], false %>

I tried different combinations like:

<%= f.check_box :invoiceable_of_Subscription_type_or_invoiceable_of_Purchase_type_status_in, { multiple: true }, type[1], false %>

But I always get a Polymorphic associations do not support computing the class. error.

Is this possible? Ransack documentation only explains how to search by a single polymorphic associated model.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You were very close to the answer.

You need to specify column name with each of the polymorphic association

use below combination :

<%= f.check_box :invoiceable_of_Subscription_type_status_or_invoiceable_of_Purchase_type_status_in, { multiple: true }, type[1], false %>

Reference : https://github.com/activerecord-hackery/ransack/wiki/Polymorphic-searches

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!