3

I'm using Active Admin 0.3.2, and my database schema includes a few has_and_belongs_to_many relationships. I can create and display records just fine, but attempting to include them in the filter section causes things to grind to a halt.

models\pin.rb:

class Pin < ActiveRecord::Base
    has_and_belongs_to_many :pin_types, :join_table => :pin_types_pins
end

models\pin_type.rb

class PinType < ActiveRecord::Base
    has_and_belongs_to_many :pins, :join_table => :pin_types_pins
end

admin\pins.rb

ActiveAdmin.register Pin do
    filter :pin_types
    ...other filters
end

The result is that the other filters appear, but there's no section at all for Pin Types.

If admin\pins.rb is this instead:

ActiveAdmin.register Pin do
    filter :pin_types, :as => :check_boxes
    ...other filters
end

I get the following:

undefined method `pin_type_ids_in' for #<MetaSearch::Searches::Pin:0xcd2c108>

What I'd like to do is allow the user to select one or many Pin Types from a set of possible choices and filter depending on whether any of the selected options apply.

Is this possible?

ccarlson
  • 41
  • 1
  • 6
  • 1
    I found the solution myself, [on GitHub](https://github.com/gregbell/active_admin/issues/515). For reference: `filter :pin_types_id, :as => :check_boxes, :collection => proc {PinType.all}` – ccarlson Oct 18 '11 at 12:36
  • if we want to create Pintype from pin then what we need to do? – Mohd Anas Nov 13 '13 at 13:03

2 Answers2

3

use the filter like this: filter :model_attribute , so if you are on the User_events and wanted to search on the user name , u'd do this filter :user_fullName

rodrigo
  • 31
  • 1
0

Note that ccarlson's answer works, but only with :check_boxes.

This is unfortunate, because the default behavior of meta_search (used to power the filter searching) does not filter out duplicates... and when you're using checkboxes, you probably don't want to see a result come up twice because it matches 2 selected options.

I ran into the undefined method error here when attempting to use as: :select, but had to bite the bullet on checkboxes.

samsmith
  • 11
  • 4