Frage

Rails 3.1, ActiveAdmin 0.3.4.

My question is somewhat similar to this one but different enough in terms of data modeling that I think it warrants its own response. Models:

class CheckoutRequest < ActiveRecord::Base  
  has_one :request_common_data, :as => :requestable, :dependent => :destroy
end

class RequestCommonData < ActiveRecord::Base
  belongs_to :requestable, :polymorphic => true
end

The RequestCommonData model has a completed field (boolean) that I'd like to be able to filter in ActiveAdmin's CheckoutRequest index page. I've tried a few different approaches to no avail, including the following:

filter :completed, :collection => proc { CheckoutRequest.all.map { |cr| cr.request_common_data.completed }.uniq }

which results in no filter being displayed. Adding :as => :select to the line, as follows:

filter :completed, :as => :select, :collection => proc { CheckoutRequest.all.map { |cr| cr.request_common_data.completed }.uniq }

results in the following MetaSearch error message:

undefined method `completed_eq' for #<MetaSearch::Searches::CheckoutRequest:0x007fa4d8faa558>

That same proc returns [true, false] in the console.

Any suggestions would be quite welcome. Thanks!

Keine korrekte Lösung

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top