Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby Spree 3.0添加到扩展中的允许属性_Ruby_Ruby On Rails 4_Spree_Strong Parameters - Fatal编程技术网

Ruby Spree 3.0添加到扩展中的允许属性

Ruby Spree 3.0添加到扩展中的允许属性,ruby,ruby-on-rails-4,spree,strong-parameters,Ruby,Ruby On Rails 4,Spree,Strong Parameters,因此,我正在进行一个spree扩展,其中我有自己的属性,我将其添加到了spree::Shipping,并在签出过程中添加了一个输入,问题是我的属性不是装运的允许属性的一部分,并且不清楚如何将其添加到允许属性中。我找到了要使用的对话 Spree::PermittedAttributes.shipment_attributes << :my_custom_attribute (),所有这些都会导致一个错误,抱怨未定义shipping_属性(因此,可能代码是在计算定义permitedat

因此,我正在进行一个spree扩展,其中我有自己的属性,我将其添加到了
spree::Shipping
,并在签出过程中添加了一个输入,问题是我的属性不是装运的允许属性的一部分,并且不清楚如何将其添加到允许属性中。我找到了要使用的对话

Spree::PermittedAttributes.shipment_attributes << :my_custom_attribute
(),所有这些都会导致一个错误,抱怨未定义
shipping_属性
(因此,可能代码是在计算定义
permitedattributes
的主文件之前运行的),或者根本没有发生任何事情。我应该将此代码放在何处以将我的属性添加到允许的属性列表中


编辑:由于人们对此似乎不清楚,我尝试了我发布的链接中列出的所有内容。让我试一下里面的东西真让人恼火。停止这样做。

如前所述,您可以将其放入
应用程序控制器中

或者,您可以覆盖整个允许的参数,将您的添加到白名单中(通过将此代码直接放入最后一个
结束后的
application\u controller.rb
,这将100%起作用,或者通过创建一个新文件(例如,在lib下,正如您已经尝试过的那样)):

“spree.rb”实际上是指
config/initializers/spree.rb
。这是spree配置的正确位置。我注意到你/那篇文章提到了各种文件,但从来没有提到过这个文件

一旦进入该文件:

Spree::PermittedAttributes.shipment_attributes << :my_custom_attribute

如果这不起作用,您需要提供更多详细信息。

“我认为最好将其添加到ApplicationController或其他与应用程序一起重新加载的文件中。您可能会遇到rails将重新加载应用程序代码,并且该类访问器上缺少属性的问题”-引用自github线程。。。你有没有试过用ApplicationController?你有没有试过把它放在一个初始值设定项中,正如你在文章更新中所建议的那样?()我还有两个自定义属性,并添加了
Spree::permitedAttributes.shipping_属性您找到其他方法了吗?因为,将它放在spree.rb中可能不是最好的方法。@anoop不,虽然我可能已经安装了fsck,所以请尝试我链接的解决方案,它们可能对您有效,即使它们对我无效。请参阅我的编辑,告诉我尝试我发布的链接中的内容。我不是有意激怒或激怒您。不过,我不认为我使用app_controller的解决方案不会影响这种情况。但是,正如你所说
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
Spree::PermittedAttributes.shipment_attributes << :my_custom_attribute
Spree::PermittedAttributes.shipment_attributes.push :my_custom_attribute