Hey, I was having trouble once the barcode is captured/scanned. In the console it has the error, ""POST http://localhost:3000/products/get_barcode 404 (Not Found)". I have checked my routes and run rake routes, and they are coming up correctly. Any idea why that may be?
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
I was just about to ask you if it was throwing the error because I'm not passing the ticket_id. I'm not the best with jQuery so I didn't know if the client required that, although as I type it this makes sense that it would.
What do you mean by "pass it into the data attribute"?
Are you saying that the client is throwing the original error I posted because it's trying to find the order, but doesn't have the ticket_id?
Hm. That's a problem because at this point the ticket_id is not accessible for me to put it in a div. Are there any other ways you can think of to do this? You don't have to write out the code, you can just let me know your ideas.
I wasn't able to figure it out, and even utilizing the hints you gave me didn't change much. All the errors are popping up in the console on the client. I'm not a jQuery guy, so I'll have to look into another solution for accomplishing this. Thanks for your help and the video is great!