2014-06-19 50 views
2

在Rails 3中,我一直在使用以下包含作用正常的作用域(在模塊中定義)。Rails 4作用域包含嵌套關聯散列

base.send :scope, :with_includes, { :include => {:questions => [:answers, :question_group, {:dependency => :dependency_conditions}]}} 

此不再內軌道4的工作原理,所以我曾嘗試將其轉換爲現在優選的方法拉姆達如下。

base.send :scope, :with_includes, -> { includes(:questions => [:answers, :question_group, {:dependency => :dependency_conditions}]) } 

這只是拋出一個異常NoMethodError Exception: undefined method includes

回答

0

嘗試用base.includes(...)拉姆達內。

基本上,你的拉姆達拍攝的self不是你記錄的類:這是其中scopesend(T)。

+0

謝謝;就是這樣。 – bigtunacan