My favorites | Sign in
Project Logo
                
Code license: MIT License
Labels: rails, rest
Blogs:
Feeds:
People details
Project owners:
  maccman

RestResponses is a couple of useful little methods to clear up your restfull controllers, turning something like this:

def update
 @user = User.find(params[:id])
 @user.update_attributes!(params[:user])
  respond_to do |wants|
     wants.html { }
     wants.xml  { render :xml => @user.to_xml(:except => :hashed_password) } 
  end	 
rescue ActiveRecord::RecordNotFound
  render :nothing => true, :status => 404
rescue ActiveRecord::InvalidRecord
  respond_to do |wants|
    wants.html { }
    wants.xml  { render :xml => @user.errors.to_xml }
   end
end

To this:

before_filter :find_user
def update
 @user.update_attributes!(params[:user])
  responds @user
end

To install: ruby script/plugin install http://rest-responses.googlecode.com/svn/trunk/rest_responses









Hosted by Google Code