Skip to content

Commit

Permalink
Use ransack_mongo
Browse files Browse the repository at this point in the history
  • Loading branch information
pencilcheck committed Jan 17, 2015
1 parent 59d8bf2 commit 0e262c9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activeadmin-mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
gem.add_runtime_dependency 'activeadmin', ['>= 1.0.0.pre', '< 2']
gem.add_runtime_dependency 'jquery-rails'
gem.add_runtime_dependency 'sass-rails', ['>= 3.1.4', '< 5.0']
# gem.add_runtime_dependency 'meta_search', '~> 1.1.3'
gem.add_runtime_dependency 'ransack_mongo', '~> 1.0.0'

gem.add_development_dependency 'rspec-rails', '~> 2.7'
end
23 changes: 23 additions & 0 deletions lib/active_admin/filters/formtastic_addons.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module ActiveAdmin
module Filters
module FormtasticAddons

def searchable_has_many_through?
false
end

def has_predicate?
!!RansackMongo::Predicate.new(RansackMongo::MongoAdapter::PREDICATES).detect_from_string(method.to_s)
end

def ransacker?
false
end

def scope?
false
end

end
end
end
2 changes: 2 additions & 0 deletions lib/active_admin/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
require 'active_admin/mongoid/document'
require 'active_admin/mongoid/helpers/collection'
require 'active_admin/mongoid/criteria'
require 'active_admin/filters/formtastic_addons'
require 'active_admin/resource_controller/data_access'

require 'active_admin/mongoid/order_clause'

Expand Down
13 changes: 13 additions & 0 deletions lib/active_admin/resource_controller/data_access.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module ActiveAdmin
class ResourceController < BaseController

module DataAccess

# Applies any Ransack search methods to the currently scoped collection.
# Both `search` and `ransack` are provided, but we use `ransack` to prevent conflicts.
def apply_filtering(chain)
@search = chain.where RansackMongo::Query.parse clean_search_params params[:q]
end
end
end
end

0 comments on commit 0e262c9

Please sign in to comment.