[英]Rails: ActiveAdmin custom filter returning errors
我正在尝试通过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>)
ActiveAdmin使用元搜索作为过滤器。 查看此示例 ,了解如何设置自定义搜索方法。
您可以使用范围:
class User < AR::Base
has_many :gpas
scope :current_gpa, where(....)
ActiveAdmin.register Athlete do
scope :current_gpa
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.