Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.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 on rails Spree::Variant的装饰器_Ruby On Rails_Spree - Fatal编程技术网

Ruby on rails Spree::Variant的装饰器

Ruby on rails Spree::Variant的装饰器,ruby-on-rails,spree,Ruby On Rails,Spree,我正在编写一个Spree扩展,其中一个模型创建了一个与Spree::Variant的一对一关系。我创建了以下装饰器: # app/models/spree/variant_decorator.rb Spree::Variant.class_eval do has_one :persomodel, class_name: 'Extension::Persomodel' end 我发现这个decorator不是通过运行控制台来计算的。查看spree_core(版本2.0.3)中的Variant

我正在编写一个Spree扩展,其中一个模型创建了一个与
Spree::Variant
的一对一关系。我创建了以下装饰器:

# app/models/spree/variant_decorator.rb
Spree::Variant.class_eval do
  has_one :persomodel, class_name: 'Extension::Persomodel'
end
我发现这个decorator不是通过运行
控制台来计算的。查看
spree_core
(版本2.0.3)中的
Variant
模型,我看到没有文件
app/model/Variant.rb
,只有一个文件
app/model/Variant/scope.rb
。我想这就是我的装饰师没有被评估的原因


那么,我该如何实现我要寻找的关系呢?

我不确定你的结论是否正确

在Spree应用程序中,通常会在application.rb中包含类似于以下内容的部分

config.to_prepare do
  ['../app/**/*_decorator*.rb'].each do |glob|
    Dir.glob(File.join(File.dirname(__FILE__), glob)) do |c|
      Rails.configuration.cache_classes ? require(c) : load(c)
    end
  end
end
这将迭代app目录中格式为*_decorator*.rb的所有文件,并根据需要要求/加载它们

如果您正在构建一个作为Rails引擎的扩展,您将放置一个类似的块:

 Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
   Rails.configuration.cache_classes ? require(c) : load(c)
 end
在engine.rb的config.to_prepare块中


在config.to_prepare块中是否有适合您的项目的适当代码?如果存在,则应评估代码。

我不确定您的结论是否正确

在Spree应用程序中,通常会在application.rb中包含类似于以下内容的部分

config.to_prepare do
  ['../app/**/*_decorator*.rb'].each do |glob|
    Dir.glob(File.join(File.dirname(__FILE__), glob)) do |c|
      Rails.configuration.cache_classes ? require(c) : load(c)
    end
  end
end
这将迭代app目录中格式为*_decorator*.rb的所有文件,并根据需要要求/加载它们

如果您正在构建一个作为Rails引擎的扩展,您将放置一个类似的块:

 Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
   Rails.configuration.cache_classes ? require(c) : load(c)
 end
在engine.rb的config.to_prepare块中


在config.to_prepare块中是否有适合您的项目的适当代码?如果存在,则应评估您的代码。

适当的文件应位于“谢谢”,您的输入很有帮助。由于某种原因,我忽略了这个文件…适当的文件应该在谢谢你,你的输入很有帮助。我出于某种原因忽略了这个文件…嗨,彼得,你说得对。我将您推荐的代码添加到了我的engine.rb文件中,现在关联可以完美地工作了。我已经看到了这种包容机制,但并没有真正意识到它。你的回答帮助了我,我学到了一些东西。非常感谢你的宝贵帮助!嗨,彼得,你说得对。我将您推荐的代码添加到了我的engine.rb文件中,现在关联可以完美地工作了。我已经看到了这种包容机制,但并没有真正意识到它。你的回答帮助了我,我学到了一些东西。非常感谢你的宝贵帮助!