Michael Law said almost 8 years ago on Decoding and Interacting with Barcodes :

I copied and pasted the code as you have it below, except my routes have 'orders' where you have 'products', and I'm only trying to find already existing orders.

The only difference is that my 'orders' routes are actually nested.

In my JS file, I have everything else exactly the same except the url in the ajax request.

$.ajax({
  type: "POST",
  url: '/orders/get_barcode',
  data: { upc: code }
});

Since my orders route is nested, when I run rake routes I get

get_barcode_ticket_orders ... POST ... /tickets/:ticket_id/orders/get_barcode(.:format) ... orders#get_barcode


In my routes file:

resources :tickets do
    resources :orders do
      post :get_barcode, on: :collection
    end
  end