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::PermittedAttributes.shipment_attributes << :my_custom_attribute
in config/initializers/spree.rb (at the end) and it worked for me – Barto