0

索引操作

@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一起使用

4

1 回答 1

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
于 2013-01-11T21:30:11.653 回答