2012-12-10 10 views
12

जानना चाहते हैं कि सक्रिय व्यवस्थापक के साथ डिफ़ॉल्ट मान के साथ फ़िल्टर करना संभव है? व्यवस्थापक उपयोगकर्ता के लिए डेटा को प्रीलोड करने के लिए यह सहायक होगा। या पैरामीटर: [क्यू] खाली है [: गुंजाइश] खालीActiveAdmin - डिफ़ॉल्ट मान के साथ फ़िल्टर

कुछ मामलों आप फ़िल्टर सेट करने के लिए यदि पैरामीटर की जरूरत है

:

filter :country, :default=>'US' 

उत्तर

18

आप before_filter

before_filter :only => [:index] do 
    if params['commit'].blank? 
     #country_contains or country_eq .. or depending of your filter type 
     params['q'] = {:country_eq => 'US'} 
    end 
    end 

युपीडी को परिभाषित करते हुए यह कर सकते हैं

तो यह बेहतर काम कर सकते हैं

before_filter :only => [:index] do 
    if params['commit'].blank? && params['q'].blank? && params[:scope].blank? 
     #country_contains or country_eq .. or depending of your filter type 
     params['q'] = {:country_eq => 'US'} 
    end 
    end 
+0

यह एक आकर्षण की तरह काम करता है। धन्यवाद Fivell! – TonyTakeshi

+0

हमेशा स्वागत है!) – Fivell

+1

यह ऐप/व्यवस्थापक/model.rb फ़ाइल के अंदर एक नियंत्रक ब्लॉक में जाना चाहिए। जैसे नियंत्रक पहले_फिल्टर ... अंत –

4

अनुकूलित Fivells जवाब scopes और डाउनलोड के साथ सही ढंग से काम करने के लिए जवाब। हैकी लगता है लेकिन नौकरी करने लगता है। टिप्पणियों में एनोटेटेड इरादा।

before_filter only: :index do 
    # when arriving through top navigation 
    if params.keys == ["controller", "action"] 
     extra_params = {"q" => {"country_eq" => "US"}} 

     # make sure data is filtered and filters show correctly 
     params.merge! extra_params 

     # make sure downloads and scopes use the default filter 
     request.query_parameters.merge! extra_params 
    end 
    end 
संबंधित मुद्दे