I am wondering what is the best practice for allowing bulk edit / update in the controller. I really can't find articles or guides on the subject.
I see that you tagged your question with REST.
To do it RESTfully, you need to think about the collection or the update itself as the resource.
Say you are working with Product objects.
You might PUT to /product_batches/[some identifier], which would call ProductBatchesController#update, but then you are stuck wondering what goes in [some identifier]. You could make ProductBatch a singular resource and then you wouldn't need an id.
Better might be to POST to /product_bulk_updates, which would call ProductBulkUpdatesController#create
class ProductBulkUpdatesController < ApplicationController def create # your magic here # - update_all if you are making the same change to all Products # - looping through the hashes in params[products] if you are passing in distinct changes to each. end end
Here's another thread: Bulk Collection Manipulation through a REST (RESTful) API
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With