Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8185 (closed enhancement: fixed)

Opened 1 year ago

Last modified 1 year ago

[PATCH] Add model schema at /new.xml to scaffold_resource template

Reported by: Klondike Assigned to: core
Priority: normal Milestone: 1.x
Component: Railties Version: edge
Severity: minor Keywords: scaffold resource xml tiny
Cc:

Description

This patch updates the scaffold_resource template for a controller, to expand the "new" action. The "new" action is given an XML respond_to block that returns the XML version of a new instance of the model.

The purpose is to provide a "schema" for a model, for a client using this model through REST remotely. The object is to give a REST client the ability to automatically figure out attributes and types, much the same as ActiveRecord uses the database. This becomes more important for clients written in languages other than Ruby, including strictly typed languages.

An example of this in a User controller:

# GET /users/new
# GET /users/new.xml
def new
  @user = User.new
  
  respond_to do |format|
    format.html # new.erb
    format.xml { render :xml => @user.to_xml }
  end
end

This will produce XML looking something like this:

<?xml version="1.0" encoding="UTF-8"?>
<user>
  <active type="boolean"></active>
  <created-at type="datetime"></created-at>
  <email></email>
  <middle-name></middle-name>
</user>

Discussion on core leading up to this: http://groups.google.com/group/rubyonrails-core/browse_thread/thread/e36b84f9c1c3fe38

Attachments

add_xml_schema_to_scaffold_resource.patch (493 bytes) - added by Klondike on 04/25/07 16:14:23.
Patch over scaffold_resource controller template.

Change History

04/25/07 16:14:23 changed by Klondike

  • attachment add_xml_schema_to_scaffold_resource.patch added.

Patch over scaffold_resource controller template.

04/25/07 16:17:39 changed by tsaleh

+1

04/25/07 17:48:43 changed by Klondike

  • summary changed from Add model schema at /new.xml to scaffold_resource template to [PATCH] Add model schema at /new.xml to scaffold_resource template.

Noted in the title that a patch was given.

04/25/07 17:51:02 changed by Klondike

  • keywords changed from activeresource scaffold resource xml to scaffold resource xml tiny.

04/25/07 22:00:16 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.