2016-05-26 20 views
1

從模型中獲取數據時出現錯誤,下面是我的場景創建了一個「ProductSearch」引擎,在ProductSearch內部我有控制器,模型,幫助器和視圖。未定義的方法all:{:conditions => {:retailer_id => [1,2]}}:Hash在rails引擎中

現在控制器的方法給出了一個錯誤,而下面執行的是控制器方法

def stores_in_mall 
    @stores ||= TenantRetailigenceRetailer. 
     for_property(@property).all(:include => :retailer, :order => 'retailers.name'). 
     reject{ |s| s.retailer.nil? || s.retailer.suite.nil? } 
    end 

下面的代碼是產品搜索型號

module ProductSearch 
    class TenantRetailigenceRetailer < ActiveRecord::Base 
     belongs_to :retailer 
     belongs_to :retailigence_retailer 
     attr_accessor :tenant_id, :retailigence_retailer_id 
     scope :for_property, lambda{ |property| 
           { :conditions => { :retailer_id => property.retailers.map(&:id) } } 
           } 

     def name 
     retailer.name 
     end 
    end 
end 
+0

您正在使用導軌4? – Thorin

+0

只是更改範圍:for_property,lambda {| property | – Thorin

+0

是的我正在使用rails 4 @Thorin – user3906755

回答

1

的代碼,如果他們返回的ActiveRecord您可以使用多個範圍關係

class Person < ActiveRecord::Base 
    scope :find_someone, -> (id) { where(id: id) } 
    scope :find_another, -> { where(type: "xyz")} 
end 

現在你可以一起使用它們像

Person.find_someone(1).find_another.all 

但是你的情況的範圍返回一個條件

{:條件=> {:retailer_id => [1,2]}}

所以'所有'方法將不起作用。

+0

是的@Mahesh你是對的,我沒有得到ActiveRecord這就是爲什麼所有的方法不工作..! – user3906755

相關問題