Created
September 26, 2008 16:26
-
-
Save joefiorini/13144 to your computer and use it in GitHub Desktop.
Code to make resource controllers more RESTful
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationResourceController < ApplicationController | |
resource_controller | |
protect_from_forgery :only => [:update, :delete] | |
index.wants.xml { render :xml => collection.to_xml, :status => :ok } | |
show do | |
failure.wants.xml { render :nothing => true, :status => 404 } | |
wants.xml do | |
unless object | |
render :nothing => true, :status => 404 | |
else | |
render :xml => object.to_xml, :status => :ok | |
end | |
end | |
end | |
update do | |
failure.wants.xml do | |
render :nothing => true, :status => :conflict if object.conflicting_name? params[:id] | |
end | |
wants.xml { render :xml => object.to_xml, :status => :ok } | |
end | |
create do | |
wants.html { } | |
wants.xml { render :xml => object.to_xml, :status => :created, :location => object_url(object) } | |
failure.wants.xml { render :nothing => true, :status => :conflict if object.conflicting_name? params[:id] } | |
end | |
destroy do | |
wants.xml { render :nothing => true, :status => :ok } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment