On Tue, Apr 24, 2007 at 10:24:55AM -0700, Eric Mill wrote:
> > I just don't really see how this enables anything new, surely
> > anything
> > javascript  can do with the schema document, could also be done with
> > the xml document received in response to /foos/1.xml?
> 
> This only works if there is at least one object saved in the database.

And if you already know an ID (unless you want go scavenging in
/foos.xml).

It seems to me you're missing a solution that's simple and obvious.
Consider this excerpt from the resource scaffolding:

  # GET /foos/1
  # GET /foos/1.xml
  def show
    @foo = Post.find(params[:id])

    respond_to do |format|
      format.html # show.erb
      format.xml  { render :xml => @foo.to_xml }
    end
  end

  # GET /foos/new
  def new
    @foo = Post.new
  end

Now, look what happens when we update the second method to look like
the first.

  # GET /foos/new
  # GET /foos/new.xml
  def new
    @foo = Post.new

    respond_to do |format|
      format.html # new.erb
      format.xml  { render :xml => @foo.to_xml }
    end
  end

Voila.  Now the HTML response and the XML response refer to the same
object.  The XML client gets the field names and types, and defaults
for the field values to boot.  And we didn't even have to touch the
Rails core.  The only thing left is the route, which I leave as an
exercise to the reader.

The disadvantage to this method is that "new" doesn't fit cleanly into
the four CRUD actions.  This was accepted as a necessary compromise
for interactive uses, but now it's creeping into the API as well.

Cheers,
Tim

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to