From 332a7e67d8fe255d395fcc810a39ca4b7b8ac681 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 21 Jan 2013 13:44:02 -0600 Subject: [PATCH] update ItemsController to show new search errors properly --- app/controllers/items_controller.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 4325595d..9a6e2908 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -1,5 +1,6 @@ class ItemsController < ApplicationController before_filter :set_query + rescue_from Item::Search::Error, :with => :search_error def index if params.has_key?(:q) @@ -20,13 +21,6 @@ class ItemsController < ApplicationController 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] } 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 elsif params.has_key?(:ids) && params[:ids].is_a?(Array) @items = Item.find(params[:ids]) @@ -114,6 +108,16 @@ class ItemsController < ApplicationController def assign_closeted! current_user.assign_closeted_to_items!(@items) if user_signed_in? 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 @query = params[:q]