openfoodnetwork
https://github.com/openfoodfoundation/openfoodnetwork
Ruby
Connect suppliers, distributors and consumers to trade local produce.
Spree::ProductSet#update_attributes
A separate method of updating products was required due to an issue with the way Rails' assign_attributes and updates_attributes behave when delegated attributes of a nested
object are updated via the parent object (ie. price of variants). Updating such attributes by themselves did not work using:
product.update_attributes( { variants_attributes: [ { id: y, price: xx.x } ] } )
and so an explicit call to update attributes on each individual variant was required. ie:
variant.update_attributes( { price: xx.x } )Edit
git clone [email protected]:openfoodfoundation/openfoodnetwork.git
cd openfoodnetwork
open app/models/spree/product_set.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Spree--ProductSet-update_attributes-for-pr
# Commit to gitgit add app/models/spree/product_set.rbgit commit -m "better docs for Spree::ProductSet#update_attributes"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Spree--ProductSet-update_attributes-for-pr
hub pull-request
# Celebrate!