开发者

Integrating meta_search gem in index with existing geocoder gem search (rails)

I have already implemented a location based search using geocoder and am having trouble开发者_开发知识库 integrating the meta_search gem. I'm trying to integrate meta_search into my object_controller index to allow users to filter and sort search results by an objects :attributes after they have already searched by location.

My object_controller:

def index 
  if params[:search].present?
   @objects = Object.near(params[:search], 50, :order => :distance).paginate(:page => params[:page], :per_page => 9)
  else
   @objects = Object.paginate(:page => params[:page], :per_page => 9)
  end
end

Any idea how best to integrate the @search into the index required by the meta_search gem?

Here is what the meta_search github recommends for the index:

def index
  @search = Article.search(params[:search])
  @articles = @search.all   # load all matching records
  # @articles = @search.relation # Retrieve the relation, to lazy-load in view
  # @articles = @search.paginate(:page => params[:page]) # Who doesn't love will_paginate?
end

Thanks so much,

Will


I believe both the geocoder and meta_search query methods return an ActiveRecord::Relation therefore you should be able to chain them:

@objects = Object.near(params[:search], 50, :order => :distance).search(params[:search]).relation.paginate(:page => params[:page], :per_page => 9)

or if you need the search object to be separate:

@search = Object.near(params[:search], 50, :order => :distance).search(params[:search])
@objects = @search.relation.paginate(:page => params[:page], :per_page => 9)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜