REST standard actions: why does "new" action have a .xml flavor?

When I generate a REST controller scaffold I get an action that looks
something like:

GET /users/new

GET /users/new.xml

def new
@user = User.new

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

end

From my understanding, the ‘new’ action initializes an instance of the
model to kind of ‘pre-populate’ the form, but nothing is saved until
the “update” action is called.

So what is a scenario where a REST web service call of “new” would
make any useful sense, like: http://www.xxx.com/users/new.xml

This is a nuance I am not following. Anyone?

Very good point! But like you said the new method might be used to pre-
populate the object. If this is the case an XML would be useful.

On Tue, Apr 1, 2008 at 2:21 PM, harm [email protected] wrote:

Very good point! But like you said the new method might be used to pre-
populate the object. If this is the case an XML would be useful.

Except that new is routed via a get request, and normally returns an
html form which does the post which is routed to the create action.

So the xml would be asking for the form representing the
“pre-populated” object to be returned in xml.


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

I believe the form in a typical new.erb file is just the sugar on the
cake. It is the underlying object (<% form_for @some_object %>) that
is interresting. Which you might want to fill in with some default
values. So the xml request would not ask for the form but for the
object.

It works very well with ActiveResource. ARes does not have any
knowledge of the attributes available on the remote resource. The
Controller#new method in that remote resource can help out by
serializing the attribute names and their data types.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs