Rails 3.2.0 - Redirecting after a JSON call is made -
i have controller action handles json requests handling datatables grid redrawing. have before_filter checks if session has been destroyed , should redirect logout action. when request ajax request, redirect happens fine. if request json, logs shows "filter chain halted :authorize rendered or redirected" not redirect page @ all. clues?
i see logs show it's processing action json:
processing usercontroller#datatable_redrawings json
my contoller method:
before_filter :auth def auth if session[:username].blank? flash[:error] = "please login." if request.xhr? render :js => "window.location = '/logout'" else respond_to |format| format.html { redirect_to :action => "logout" } end end end end
a redirection isn't restful, nor sending js when client expecting json response. should send unauthorized (401) http status code or similar.
before_filter :auth def auth if session[:username].blank? respond_to |format| format.json { render :json => [], :status => :unauthorized } format.html { redirect_to :action => "logout" } end return false end end
Comments
Post a Comment