Ask A Question

Notifications

You’re not receiving notifications from this thread.

Rails + Javascript question

Ignacio Alonso asked in Rails

Hey guys,

I have an app for generating orders containg products. I'm currently using a “cart” through table that helps me connect both orders and products. I would like to have a list of products where users can select what they want from the list via checkbox for e.g. and then add them to an array that would be sent to my controller but I don’t want to reload page on each product add from the list. What would be the best way to add the X number of products to the params after user ’adds' them to the cart and press send?

Reply

I would recommend accumulating the products and their assocaited quantities as objects inside a local JS array. When the end-user presses "send", you can catch that event and build/send a FormData() object via Rails.ajax. See my example over at JSFiddle @ https://jsfiddle.net/pupdogg/okagmx6p/8/ as I'm not sure how to embed it here. I hope this helps!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.