更改元搜索参数

时间:2013-01-11 21:09:00

标签: ruby-on-rails meta-search

指数行动

@search = Project.search(params[:search])
@projects = @search.order('created_at desc').paginate(:page => params[:page], :per_page => 100)
@total_projects = Project.count
respond_to do |format|
  format.html 
  format.mobile
  format.json { render :json => @projects }
end    

如果params[:search][:stage_in]存在并且它等于“time_end”,我想像params[:search][:stage_in] == "started"一样更改它,它可以与@search

一起使用

1 个答案:

答案 0 :(得分:0)

为了清洁,我会为你做一个单独的方法。也是最后一部分假设是'=='?:

@search = Project.search(search_params(params))
@projects = @search.order('created_at desc').paginate(:page => params[:page], :per_page => 100)
@total_projects = Project.count
respond_to do |format|
  format.html 
  format.mobile
  format.json { render :json => @projects }
end  

def search_params(params)
  params[:search][:stage_in] = "started" if params[:search][:stage_in] == "time_end"
  params
end