Replace this common pattern in controllers:
@tags = Tag.search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
with this:
@tags = Tag.paginated_search(params)
`search_count` is used to skip doing a full page count when we're not
doing a search (on the assumption that the number of results will be
high when not constrained by a search). We didn't do this consistently
though. Refactor to do this in every controller.
45 lines
1.0 KiB
Ruby
45 lines
1.0 KiB
Ruby
class SavedSearchesController < ApplicationController
|
|
respond_to :html, :xml, :json, :js
|
|
|
|
def index
|
|
@saved_searches = saved_searches.paginated_search(params)
|
|
respond_with(@saved_searches)
|
|
end
|
|
|
|
def labels
|
|
@labels = SavedSearch.search_labels(CurrentUser.id, params[:search])
|
|
respond_with(@labels)
|
|
end
|
|
|
|
def create
|
|
@saved_search = saved_searches.create(saved_search_params)
|
|
respond_with(@saved_search)
|
|
end
|
|
|
|
def destroy
|
|
@saved_search = saved_searches.find(params[:id])
|
|
@saved_search.destroy
|
|
respond_with(@saved_search)
|
|
end
|
|
|
|
def edit
|
|
@saved_search = saved_searches.find(params[:id])
|
|
end
|
|
|
|
def update
|
|
@saved_search = saved_searches.find(params[:id])
|
|
@saved_search.update(saved_search_params)
|
|
respond_with(@saved_search, :location => saved_searches_path)
|
|
end
|
|
|
|
private
|
|
|
|
def saved_searches
|
|
CurrentUser.user.saved_searches
|
|
end
|
|
|
|
def saved_search_params
|
|
params.fetch(:saved_search, {}).permit(%i[query label_string disable_labels])
|
|
end
|
|
end
|