diff --git a/app/assets/javascripts/rails_admin/ra.filter-box.js b/app/assets/javascripts/rails_admin/ra.filter-box.js
index 1df939ea29..23a07d97b5 100644
--- a/app/assets/javascripts/rails_admin/ra.filter-box.js
+++ b/app/assets/javascripts/rails_admin/ra.filter-box.js
@@ -39,9 +39,9 @@
'' +
'' +
''
- var additional_control =
- ' ' +
- ' ' +
+ var additional_control =
+ ' ' +
+ ' ' +
'';
break;
case 'enum':
@@ -72,6 +72,18 @@
''
var additional_control = ' ';
break;
+ case 'has_and_belongs_to_many_association':
+ var control = ''
+ var additional_control = ' ';
+ break;
default:
var control = ' ';
break;
diff --git a/app/controllers/rails_admin/main_controller.rb b/app/controllers/rails_admin/main_controller.rb
index 6c890f98d7..7cdc23d4fd 100644
--- a/app/controllers/rails_admin/main_controller.rb
+++ b/app/controllers/rails_admin/main_controller.rb
@@ -119,7 +119,7 @@ def check_for_cancel
end
def get_collection(model_config, scope, pagination)
- associations = model_config.list.fields.select {|f| f.type == :belongs_to_association && !f.polymorphic? }.map {|f| f.association[:name] }
+ associations = model_config.list.fields.select {|f| (f.type == :belongs_to_association || f.type == :has_and_belongs_to_many_association) && !f.polymorphic? }.map {|f| f.association[:name] }
options = {}
options = options.merge(:page => (params[:page] || 1).to_i, :per => (params[:per] || model_config.list.items_per_page)) if pagination
options = options.merge(:include => associations) unless associations.blank?
diff --git a/app/views/rails_admin/main/index.html.haml b/app/views/rails_admin/main/index.html.haml
index e4b2053068..a87b3ef298 100644
--- a/app/views/rails_admin/main/index.html.haml
+++ b/app/views/rails_admin/main/index.html.haml
@@ -36,7 +36,11 @@
filter_for_field = duplet[1]
filter_name = filter_for_field.keys.first
filter_hash = filter_for_field.values.first
- field = @filterable_fields.find{ |field| field.name == filter_name.to_sym }
+ field = @filterable_fields.find do |field|
+ filter_name = filter_name.pluralize if
+ field.type == :has_and_belongs_to_many_association
+ field.name == filter_name.to_sym
+ end
field_options = case field.type
when :enum
options_for_select(field.with(:object => @abstract_model.model.new).enum, filter_hash['v'])
diff --git a/lib/rails_admin/adapters/active_record.rb b/lib/rails_admin/adapters/active_record.rb
index ad7a4b347a..f7cba18bdf 100644
--- a/lib/rails_admin/adapters/active_record.rb
+++ b/lib/rails_admin/adapters/active_record.rb
@@ -134,6 +134,10 @@ def filter_conditions(filters, fields = config.list.fields.select(&:filterable?)
filters.each_pair do |field_name, filters_dump|
filters_dump.each do |filter_index, filter_dump|
field_statements = []
+ unless fields.find{ |f| f.name.to_s == field_name.pluralize }.nil?
+ # :has_and_belongs_to_many_association
+ field_name = field_name.pluralize
+ end
fields.find{|f| f.name.to_s == field_name}.searchable_columns.each do |column_infos|
statement, value1, value2 = build_statement(column_infos[:column], column_infos[:type], filter_dump[:v], (filter_dump[:o] || 'default'))
field_statements << statement if statement.present?