Search code examples
spreeransack

Taxon queries in Spree API


I'm trying to run searches using ransack queries, but I'm getting invalid search term results on the following /api/v1/products?q[classifications_taxon_id_eq]=3. Can someone please tell me what I'm doing wrong?

I deliberately set ransack to not ignore invalid terms, just to try to figure out what's going on.

The error I get is something like:

Invalid search term classifications_taxon_id_eq

Solution

  • You need to whitelist classifications in the product model:

    After that in the classification model, you need to whitelist the taxon attribute.

    https://github.com/spree/spree/blob/master/core/app/models/spree/product.rb#L117