>   # 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.

I played with exactly this last night, and I think it *is* the better
solution, and of course far less work.  The major problem is that this
won't include any associations, even if :include is passed as a param,
because all the associations are either an empty array or nil.
Possible solutions are to add an :include_associations
or :include_empty argument or something to to_xml, or to change
to_xml's default behavior to include associations in the XML
when :include'd, whether they're empty or not.

> The only thing left is the route, which I leave as an
> exercise to the reader.

Actually, new.xml is already given for free.  Sweet!


--~--~---------~--~----~------------~-------~--~----~
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