2014-06-19 102 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