Skip to content

RESTful Scaffolding

Yvem edited this page Jan 18, 2011 · 4 revisions

Table of Contents

Introduction

ActiveScaffold handle all the REST operations. Active scaffold supports by default the following formats :

  • HTML
  • js
  • XML
  • json
  • yaml
ActiveScaffold defines a number of methods above and beyond the standard RESTful CRUD. All of this extra configuration has been packaged up in a flag that you can set in your routes.rb. To configure a RESTful scaffold, make a map.resources entry like the below:

map.resources :users, :active_scaffold => true

Examples

We suppose a common "thing" ressource.

GET the thing with id 1 in XML

GET http://my-server/things/1.xml

GET the thing with id 3 in YAML

GET http://my-server/things/3.yaml

GET the things with property "special" in YAML

GET http://my-server/things.yaml?property=special

PUT a new thing in XML

  • PUT http://my-server/things.xml
  • data = <?xml version='1.0' encoding='UTF-8'?><record><designation>special thing</designation><quantity>3</quantity></record>
  • content_type => :xml
NOTE : you must use "record" as the root element, regardless of the name of your ressource.

PUT a new thing in JSON

(user note : I have never been able to PUT in another format than XML. If someone can help...)

Clone this wiki locally