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

**URL:** <https://www.ruby-forum.com/t/rest-standard-actions-why-does-new-action-have-a-xml-flavor/133576>\
**Category:** Rails\
**Created:** [April 1, 2008, 8:09pm UTC](https://www.ruby-forum.com/t/rest-standard-actions-why-does-new-action-have-a-xml-flavor/133576 "2008-04-01T20:09:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [April 1, 2008, 8:09pm UTC](https://www.ruby-forum.com/t/rest-standard-actions-why-does-new-action-have-a-xml-flavor/133576/1 "2008-04-01T20:09:49Z")

</div>

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: [XXX Sex - Free Porn Videos at XXX.com](http://www.xxx.com/users/new.xml)

This is a nuance I am not following. Anyone?

---

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [April 1, 2008, 8:22pm UTC](https://www.ruby-forum.com/t/rest-standard-actions-why-does-new-action-have-a-xml-flavor/133576/2 "2008-04-01T20:22:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [April 2, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/rest-standard-actions-why-does-new-action-have-a-xml-flavor/133576/3 "2008-04-02T14:15:06Z")

</div>

On Tue, Apr 1, 2008 at 2:21 PM, harm [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [April 2, 2008, 2:25pm UTC](https://www.ruby-forum.com/t/rest-standard-actions-why-does-new-action-have-a-xml-flavor/133576/4 "2008-04-02T14:25:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pito](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e68b1a/32.png) [@Pito](https://www.ruby-forum.com/u/Pito)\
**Post date:** [April 2, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/rest-standard-actions-why-does-new-action-have-a-xml-flavor/133576/5 "2008-04-02T16:24:21Z")

</div>

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.
