Updating Multiple Fields with Ajax

A few months ago I was working out how to deal with multiple database entries at the same time.  We were using a CSV file to import clients.  Each client could have multiple account numbers.  For each account number, there would be an additional line with all the same info, except for the account number.

In other words, after uploading, there would be multiple clients with the same info but each with different account numbers.  I created another view to merge these clients into one client, but I needed a way to update each client without an http request for each one.

This app is a very simple mockup of how to update multiple objects in your database from a single view.  It uses jquery and ajax to send a request to the database each time you change a value in the select box.  Change the select box values, then click on the “All Users” link to see the changes.

In order to get the ajax to work with strong params, I had to use params.fetch in the update action in the controller

The code is on github here.

Leave a Reply

Your email address will not be published. Required fields are marked *