0

I tried meta_search, but after adding "include MetaSearch::Searches::ActiveRecord" into my model, it raised an error as "undefined method `joins_values'" when run "MyModel.search(params[:search])"

I think I dont need full text, so I think following gems are not suitable for my project now:: mongoid_fulltext mongoid-sphinx sunspot_mongoid mongoid_search

I tried a old gem named scoped-search I can make it work for example:

get :search do
  @search        = Notification.scoped_search(params[:search]
  search_scope   = @search.scoped
  defaul_scope   = current_user.notifications
  result_scope   = search_scope.merge defaul_scope
  @notifications = result_scope

  render 'notifications/search'
end

but it will be allow to call any scopes in my model.

Is there any "best practice" for doing this job ?

RainChen
  • 531
  • 4
  • 10

1 Answers1

0

If you want limit the scope you want use on your scoped_search you can filter your params[:search] like :

def limit_scope_search
  params[:search].select{|k,v| [:my_scope, :other_scope_authorized].include?(k) }
end
shingara
  • 46,608
  • 11
  • 99
  • 105
  • I'm really miss the "search_methods" by meta_search gem, it's using for define a white list for which scopes can be used in the search form. Maybe it's not a bad idea to filter the scarchable scopes in controller, I think it's OK for me. But the point of my question is "is there any plugin for complicated searching with mongoid (like meta_search for ActiveRecord)?" – RainChen Apr 16 '12 at 08:24