Skip to content

Instantly share code, notes, and snippets.

@jeffreyiacono
Created January 29, 2011 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffreyiacono/802152 to your computer and use it in GitHub Desktop.
Save jeffreyiacono/802152 to your computer and use it in GitHub Desktop.
widgets controller
class WidgetsController < ApplicationController
def destroy
@widget = Widget.find(params[:id])
respond_to do |format|
if @widget.delete
format.html { flash[:notice] = "Item Removed"; redirect_to widgets_path }
# change format.json to format.js and it works properly
format.js { render :status => :ok }
else
format.html { flash[:alert] = "Something went terribly wrong"; redirect_to widgets_path }
# change format.json to format.js and it works properly
format.js { render :json => @widget.errors, :status => :unprocessable_entity }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment