So I'm making a spree extension in which I have my own attribute that I added to Spree::Shipment
and added an input during the checkout process, the problem is my attribute is not part of the permitted attributes for shipments, and it is not clear how to add it to the permitted attributes. I found the conversation on this pull req which says to use
Spree::PermittedAttributes.shipment_attributes << :my_custom_attribute
However, it is unclear where do I put this!?
"Oh, put it in spree.rb
"
This doesn't help. I have tried putting this code in
lib/spree.rb
lib/spree/permitted_attributes.rb
lib/spree_decorator.rb
lib/spree/permitted_attributes_decorator.rb
(as suggested here) and all of these result in either an error complaining about shipment_attributes
not being defined (so presumably the code is run before the main file defining PermittedAttributes
is evaluated) or simply nothing happens. Where should I put this code to add my attribute to the list of permitted attributes?
Edit: Since this seems unclear to people, I have tried all of the things listed in the links I have posted. Telling me to try the things in them is quite infuriating. Stop doing that.
"spree.rb" actually means config/initializers/spree.rb
. This is the proper place for spree config. I noticed you/that article mentioned various files, but never this file.
Once in this file either:
Spree::PermittedAttributes.shipment_attributes << :my_custom_attribute
as you mentioned or
Spree::PermittedAttributes.shipment_attributes.push :my_custom_attribute
If that doesn't work you will need to provide more detail.
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