RESTful Rails plugin
Plugin details
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 documentationEdit plugin | (0 older versions) | Last edited by: hardway, about 1 year ago

