Spree 3.0 add allowed attributes to extension

So, I create a spree extension in which I have my own attribute, which I added to Spree::Shipment , and added input during the verification process, the problem is that my attribute is not part of the allowed attributes for shipments and it is unclear how to add it to allowed attributes. I found a conversation on this pull req that says to use

 Spree::PermittedAttributes.shipment_attributes << :my_custom_attribute 

However, it is not clear where I can put this ??

"Oh, put it in spree.rb "

This will not help. I 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 this leads to the fact that the error causing the complaint about shipment_attributes is not defined (so the code is supposedly executed before the main file that defines PermittedAttributes is evaluated), or just nothing happens. Where should I put this code to add my attribute to the list of allowed attributes?


Edit: since this seems incomprehensible to people, I tried all the things listed in the links I posted. Telling me to try something in them is pretty annoying. Stop doing this.

+7
ruby ruby-on-rails-4 strong-parameters spree
source share
2 answers

"spree.rb" actually means config/initializers/spree.rb . This is the right place to configure spree. I noticed that you / in this article mentioned different files, but never this file.

In this file:

 Spree::PermittedAttributes.shipment_attributes << :my_custom_attribute 

as you mentioned, or

 Spree::PermittedAttributes.shipment_attributes.push :my_custom_attribute 

If this does not work, you will need to provide more details.

+2
source share

As said here , you can only put it in the ApplicationController .

Or you can override all valid_parameters by adding them to the white list (by simply entering this code in application_controller.rb after the last end , which will be 100% executed, or by creating a new file (for example, under lib, as you have already tried)) :

 module Spree module PermittedAttributes # bunch of code @@checkout_attributes = %i( email use_billing shipping_method_id coupon_code my_custom_attribute ) # bunch of code end end 
0
source share

All Articles