update ItemsController to show new search errors properly

This commit is contained in:
Emi Matchu 2013-01-21 13:44:02 -06:00
parent cded361f73
commit 332a7e67d8

View file

@ -1,5 +1,6 @@
class ItemsController < ApplicationController class ItemsController < ApplicationController
before_filter :set_query before_filter :set_query
rescue_from Item::Search::Error, :with => :search_error
def index def index
if params.has_key?(:q) if params.has_key?(:q)
@ -20,13 +21,6 @@ class ItemsController < ApplicationController
format.json { render :json => {:items => @items, :total_pages => @items.total_pages} } format.json { render :json => {:items => @items, :total_pages => @items.total_pages} }
format.js { render :json => {:items => @items, :total_pages => @items.total_pages}, :callback => params[:callback] } format.js { render :json => {:items => @items, :total_pages => @items.total_pages}, :callback => params[:callback] }
end end
rescue Item::SearchError
@items = []
respond_to do |format|
format.html { flash.now[:alert] = $!.message }
format.json { render :json => {:error => $!.message} }
format.js { render :json => {:error => $!.message}, :callback => params[:callback] }
end
end end
elsif params.has_key?(:ids) && params[:ids].is_a?(Array) elsif params.has_key?(:ids) && params[:ids].is_a?(Array)
@items = Item.find(params[:ids]) @items = Item.find(params[:ids])
@ -114,6 +108,16 @@ class ItemsController < ApplicationController
def assign_closeted! def assign_closeted!
current_user.assign_closeted_to_items!(@items) if user_signed_in? current_user.assign_closeted_to_items!(@items) if user_signed_in?
end end
def search_error(e)
@items = []
respond_to do |format|
format.html { flash.now[:alert] = e.message; render }
format.json { render :json => {:error => e.message} }
format.js { render :json => {:error => e.message},
:callback => params[:callback] }
end
end
def set_query def set_query
@query = params[:q] @query = params[:q]