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 } )

Source | Google | Stack overflow

Edit

git clone [email protected]:openfoodfoundation/openfoodnetwork.git

cd openfoodnetwork

open app/models/spree/product_set.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Spree--ProductSet-update_attributes-for-pr


# Commit to git

git add app/models/spree/product_set.rbgit commit -m "better docs for Spree::ProductSet#update_attributes"


# Open pull request

gem 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!