OiO.lk Blog javascript Sending Nil value to Rails API in Query String from JS
javascript

Sending Nil value to Rails API in Query String from JS


I’m querying a Searchkick endpoint where I want to find all results where a field is nil.

The query in the console

Product.search('*', where: { category_id: nil })

correctly returns results.

When passed from the client nil, null and all others are interpreted as strings so my query becomes

Product.search('*', where: { category_id: 'nil' })

Is there a rails way or a specific encoding to use for query strings to allow it to be correctly parsed as nil without diving into the params hash and searching for strings?

Thank you



You need to sign in to view this answers

Exit mobile version