Plugins - Rest-Responses

StarAdd to favorites

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

Alexander MacCaw

http://code.google.com/p/rest-responses/

http://rest-responses.googlecode.com/svn/trunk/rest_responses

Rails' (MIT)

  • Currently 3.7/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Controllers

Tags

Comments

Add a comment

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?