2015-02-11 43 views
0

我試圖結合has_scope和ransack。在搜索結果中包含選中的has_scope

這些組件中的每一個都完美地工作。但是,當我試圖合併它們時,它們會相互覆蓋。例如,如果我選擇一個作用域,結果將被適當地過濾,但是一旦我使用來自ransack的search_form來進一步過濾結果,範圍就會被刪除。反過來也是如此。

這是如何實現的?

感謝您的幫助。

請參閱下面的我的嘗試。

has_scope :upward_trending, :type => :boolean 
has_scope :downward_trending, :type => :boolean 
has_scope :all, :type => :boolean 

def index 
    @has_scope = apply_scopes(Product).all 
    @q = @has_scope.search(params[:q]) 
    @products = apply_scopes(@q.result.page(params[:page]).per(30)) 
end 

回答

0

隨着搜查的新ransackable_scopes功能,就不再需要has_scope

我能做到這一點是這樣的:

def self.ransackable_scopes(auth_object = nil) 
    [:upward_trending, :downward_trending, :seven_days, :thirty_days, :six_months, :twelve_months, :all_time] 
end 

然後我能中洗劫調用這些示波器如所須。

所以要回答這個問題,使用這個新功能,範圍已經集成,我們都很好。

相關問題