RESTful Rails plugin

Plugin details

This plugin extends Ruby on Rails to allow more RESTful applications to be written.

Websitehttp://rubyforge.org/projects/restful-rails/ Repositorysvn://rubyforge.org/var/svn/restful-rails/trunk Author Dan Kubb Tags Rest LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install svn://rubyforge.org/var/svn/restful-rails/trunk

Simple example
================

Here's a sample controller using per-method dispatching and conditional request handling:

   class BookController < ApplicationController
     include RestController::Base

     resource :new do |r|
       conditions << @book = Book.new

       r.get(:cache_as => :public, :for => 1.hour)
     end

     resource :collection do |r|
       conditions << @books = Book.find(:all)

       r.post do
         @book = Book.new(params[:book])
         if @book.save
           render_post_success :action => 'by_id', :id => @book
         else
           render :action => 'new', :status => HTTP::Status::UNPROCESSABLE_ENTITY
         end
       end
     end

     resource :by_id do |r|
       conditions << @book = Book.find(params[:id])

       r.put do
         @book.attributes = params[:book]
         if @book.save
           render_put_success
         else
           render :status => HTTP::Status::UNPROCESSABLE_ENTITY
         end
       end

       r.delete do
         if @book.destroy
           render_delete_success :id => nil
         else
           render :status => HTTP::Status::UNPROCESSABLE_ENTITY
         end
       end
     end
   end

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, about 1 year ago