2013-10-28 44 views
0

我想安裝我的ActiveAdmin安裝自定義過濾器,它返回一些錯誤。Rails:ActiveAdmin自定義過濾器返回錯誤

用戶模型:

class User < AR::Base 
    has_many :gpas 

    def current_gpa 
    return nil if gpas.blank? 
    @current_gpa ||= (gpas.where(year: classification).first || gpas.order("updated_at DESC").first) 
    end 

end 

ActiveAdmin:

ActiveAdmin.register Athlete do 
    filter :current_gpa_value, as: :string 
end 

我得到的錯誤是: ActionView::Template::Error (undefined method current_gpa_value_contains for #<MetaSearch::Searches::User:0x007f982df8fd28>)

回答

0

ActiveAdmin使用垂直搜索的過濾器。看看這個example如何設置自定義搜索方法。

0

你可以使用範圍:

class User < AR::Base 
    has_many :gpas 
scope :current_gpa, where(....) 



ActiveAdmin.register Athlete do 
    scope :current_gpa 
end