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
Ruby on rails Rails Draper用于嵌套模型的未定义方法_Ruby On Rails_Ruby On Rails 4_Draper - Fatal编程技术网

Ruby on rails Rails Draper用于嵌套模型的未定义方法

Ruby on rails Rails Draper用于嵌套模型的未定义方法,ruby-on-rails,ruby-on-rails-4,draper,Ruby On Rails,Ruby On Rails 4,Draper,我的应用程序中有各种关联模型。我已经设置了Draper,以便在父类初始化时装饰关联 我有以下课程: Customer (has_many :accounts) Account (belongs_to :customer && has_many :facilities && has_one :contact) Contact (belongs_to :account) Facility (belongs_to :account) 我启动了一个装饰师,如下所示:

我的应用程序中有各种关联模型。我已经设置了Draper,以便在父类初始化时装饰关联

我有以下课程:

Customer (has_many :accounts)
Account  (belongs_to :customer && has_many :facilities && has_one :contact)
Contact  (belongs_to :account)
Facility (belongs_to :account)
我启动了一个装饰师,如下所示:

@customer = Customer.find_by(:token => params[:token]).decorate
在my account\u decorator中添加了以下内容:

decorates_association :contact
decorates_association :facilities
…在我的客户装饰师中,我有:

decorates_association :accounts
我遇到的问题是,facility_decorator中定义的任何方法都会显示未定义的方法异常。接触式装饰器工作得非常好。我已经确定我的AR映射是正确的,所以不可能是这样


有什么建议吗?

我通过急切地加载关联解决了这个问题

@customer = Customer.eager_load({ :account => [:facilities]}).find_by(:token => params[:token]).decorate

这也提高了整体查询时间,所以我对这个解决方案很满意

也许
设施
装饰器有一个不相关的问题。您是否尝试过删除关联并仅实例化修饰的
设施
,只是为了消除这种情况?@Ninjarabi,我已经测试过实例化设施并使用.decoration。在这种情况下,这似乎是可行的,因为我可以通过它的外观访问FacilityCorlator方法,
联系人
设施
之间没有区别。在没有看到所有代码的情况下,很难理解这一点。我会尝试通过将
帐户
联系人
之间的关系更改为
也有许多
来消除这些因素,并看看它是否仍然有效。然后我会尝试在这两个模型之间复制部分代码,直到我发现是什么让“联系人”起作用,而
facility
不起作用。