简体   繁体   中英

Rails: ActiveAdmin custom filter returning errors

I am trying to setup a custom filter with my ActiveAdmin installation and it is returning some errors.

User Model:

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

The error I get is: ActionView::Template::Error (undefined method current_gpa_value_contains for #<MetaSearch::Searches::User:0x007f982df8fd28>)

ActiveAdmin uses metasearch for filters. Check out this example of how to set up a custom search method.

You could use scopes:

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



ActiveAdmin.register Athlete do
  scope :current_gpa
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM