0
votes

I am trying add a custom filter in active admin which can filter status by name. Status is stored in Order table where 0 or 1 represent 'pending'. I am using ransacker to return filtered orders but it is giving me error.

      PG::UndefinedFunction: ERROR:  operator does not exist: bigint

Can anyone help me to figure out how to resolve this error?

I have tried to change my ransack method but to no avail. Here is my code:

In orders admin page:

    filter :status_str, label: "Order Status"

In order model:

   ransacker :status_str,
        :formatter => -> (coupon_id) {
          if (coupon_id == 'PENDING')
            ids  = Order.all.where("status = 0 OR status = 1").map(&:id)
          else
            ids = Order.all.map(&:id)
          end
          (ids.empty?) ? ids << 0: ids #activeadmin translates the queries into IN operator, may get syntax error if empty
          # id = 0 is non-existent in Users as id >= 1
          ids #maybe is not needed
        } do |parent|
parent.table[:id]end

I expect the filtered results to show on admin.

1

1 Answers

0
votes

Try this - Order.where(status: [0, 1]).map(&:id)

inspite of Order.all.where("status = 0 OR status = 1").map(&:id)