{"action":"created","issue":{"url":"https://api.github.com/repos/activeadmin/activeadmin/issues/3712","labels_url":"https://api.github.com/repos/activeadmin/activeadmin/issues/3712/labels{/name}","comments_url":"https://api.github.com/repos/activeadmin/activeadmin/issues/3712/comments","events_url":"https://api.github.com/repos/activeadmin/activeadmin/issues/3712/events","html_url":"https://github.com/activeadmin/activeadmin/issues/3712","id":52961429,"number":3712,"title":"Custom filters for Active Admin (e.g. filter by the count of child models)","user":{"login":"azangru","id":6834224,"avatar_url":"https://avatars.githubusercontent.com/u/6834224?v=3","gravatar_id":"","url":"https://api.github.com/users/azangru","html_url":"https://github.com/azangru","followers_url":"https://api.github.com/users/azangru/followers","following_url":"https://api.github.com/users/azangru/following{/other_user}","gists_url":"https://api.github.com/users/azangru/gists{/gist_id}","starred_url":"https://api.github.com/users/azangru/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/azangru/subscriptions","organizations_url":"https://api.github.com/users/azangru/orgs","repos_url":"https://api.github.com/users/azangru/repos","events_url":"https://api.github.com/users/azangru/events{/privacy}","received_events_url":"https://api.github.com/users/azangru/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2014-12-27T17:17:21Z","updated_at":"2015-01-20T15:48:38Z","closed_at":"2014-12-27T21:58:45Z","body":"Hi,\r\n\r\nI’m using Active Admin version 1.0.0pre. What I would like to do, is to create a filter for the index page of a model which would filter by the count of the instances of an associated model. Here’s an example.\r\n\r\nFor simplicity, let’s call one model Parent, and the other model Child, so that\r\n\r\n    class Parent < ActiveRecord::Base\r\n       has_many :children \r\n    end\r\n\r\n    class Child < ActiveRecord::Base\r\n       belongs_to :parent \r\n    end\r\n\r\nWhat I would like to create in `admin/parent.rb`, is a filter that will show parents that have a particular number of children (or who have more than or less than a certain number of children):\r\n\r\n    filter :number_of_children, as: :numeric\r\n\r\nObviously, this filter wouldn't work as written, because the `Parent` model doesn't have a `number_of_children` field. I looked into using Ransacker as discussed [here](http://cavewall.jaguardesignstudio.com/2014/05/01/activeadmin-filters-with-ransack/), but couldn't quite figure out the syntax of how to write my query. Apparently, at some point it was possible to make custom filters that would filter by scopes (as discussed [here](https://gist.github.com/rdj/1057991)), but this doesn't work any longer.\r\n\r\nWhat would be a way to make such a filter in Active Admin version 1.0.0pre? Is it possible at all?"},"comment":{"url":"https://api.github.com/repos/activeadmin/activeadmin/issues/comments/70675164","html_url":"https://github.com/activeadmin/activeadmin/issues/3712#issuecomment-70675164","issue_url":"https://api.github.com/repos/activeadmin/activeadmin/issues/3712","id":70675164,"user":{"login":"timoschilling","id":165599,"avatar_url":"https://avatars.githubusercontent.com/u/165599?v=3","gravatar_id":"","url":"https://api.github.com/users/timoschilling","html_url":"https://github.com/timoschilling","followers_url":"https://api.github.com/users/timoschilling/followers","following_url":"https://api.github.com/users/timoschilling/following{/other_user}","gists_url":"https://api.github.com/users/timoschilling/gists{/gist_id}","starred_url":"https://api.github.com/users/timoschilling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timoschilling/subscriptions","organizations_url":"https://api.github.com/users/timoschilling/orgs","repos_url":"https://api.github.com/users/timoschilling/repos","events_url":"https://api.github.com/users/timoschilling/events{/privacy}","received_events_url":"https://api.github.com/users/timoschilling/received_events","type":"User","site_admin":false},"created_at":"2015-01-20T15:48:38Z","updated_at":"2015-01-20T15:48:38Z","body":"Ok, I understand.\r\n\r\nI don't have the time to write the whole code, but I can point you in the right direction.\r\n\r\nWith Ransack you can search via relations:\r\n```ruby\r\nfilter :addresses_city # assdresses = relation table name, city = column name\r\n```\r\n\r\nNo you only need to create a list uniq list with all cities"}}