I'd like to be able to filter devise users in active admin so that I can show a list of users, then filter those users by what role they have.
What I have is:
class User < ActiveRecord::Base
has_many :user_permissions
has_many :roles, :through => :user_permissions
class Role < ActiveRecord::Base
has_many :user_permissions
has_many :users, :through => :user_permissions
class UserPermission < ActiveRecord::Base
belongs_to :user, :dependent => :destroy
belongs_to :role
Then the filter is:
ActiveAdmin.register User do
filter :roles, as: :select, collection: proc { Role.all }
But what I get is this error:
undefined method `role_ids_eq' for #<MetaSearch::Searches::User:0x0000012a2f7170>
I don't know about active admin working of filters but if you are talking about queries filter then this will work-
User.where(:role => 'admin')
Note: The above query will give all the users with the role admin
.
As mentioned, Rails 3 introduces a new query interface for performing finds in Active Record.
http://railscasts.com/episodes/202-active-record-queries-in-rails-3
try something like:
ActiveAdmin.register User do
filter :user_roles, as: :select, collection: proc { Role.all }
if the relationship is okay that should work
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.