Pito
2008-Apr-01 18:08 UTC
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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
harm
2008-Apr-01 18:21 UTC
Re: REST standard actions: why does "new" action have a .xml flavor?
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 Apr 1, 8:08 pm, Pito <pitosa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rick DeNatale
2008-Apr-02 12:14 UTC
Re: REST standard actions: why does "new" action have a .xml flavor?
On Tue, Apr 1, 2008 at 2:21 PM, harm <harmaarts-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
harm
2008-Apr-02 12:24 UTC
Re: REST standard actions: why does "new" action have a .xml flavor?
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. On Apr 2, 2:14 pm, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, Apr 1, 2008 at 2:21 PM, harm <harmaa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 Rubyhttp://talklikeaduck.denhaven2.com/--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AndyV
2008-Apr-02 14:23 UTC
Re: REST standard actions: why does "new" action have a .xml flavor?
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. On Apr 1, 2:08 pm, Pito <pitosa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---