sachin238-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Dec-06 06:15 UTC
Implementation of rest in ROR
Hi all, I am new to ROR world. I know the REST conceptually but find the difficulties in implementation can anybody guide me that which is the best book which i have to read. also some good links of implementation of rest in ROR. If anybody made a small application to restful in rails please forward me that application. i found some demo but i didn''t understand for what purpose they use format.xml def update @forum.update_attributes!(params[:forum]) respond_to do |format| format.html { redirect_to @forum } format.xml { head 200 } end end please help me i want to learn implementation of rest in ROR --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
format.xml is useless unless you want to return an XML file containing whatever is being returned in the action. You dont need that line, or the responds_to if you''re only going to have one thing it responds_to. I don''t know why format.xml is included and if someone could inform us why, that would be great :) On Dec 6, 2007 4:45 PM, sachin238-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <sachin238-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > I am new to ROR world. I know the REST conceptually but find the > difficulties in implementation can anybody guide me that which is the > best book which i have to read. also some good links of implementation > of rest in ROR. > > If anybody made a small application to restful in rails please forward > me that application. > > i found some demo but i didn''t understand for what purpose they use > format.xml > > def update > @forum.update_attributes!(params[:forum]) > respond_to do |format| > format.html { redirect_to @forum } > format.xml { head 200 } > end > end > > please help me i want to learn implementation of rest in ROR > > >-- Ryan Bigg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Here is the book to start with: http://www.pragprog.com/titles/rails2 This has a section on REST and Rails that will explain things to you. I would also highly recommend the Peepcode screencast on RESTful Rails: http://peepcode.com/ This line: format.xml { head 200 } or can also be written format.xml { head :ok } is used to inform a non-browser request (say from curl) that the PUT to the existing forum resource was successful. It does not need to return the XML of the object because the client already know what that is, because it just PUT it to the service. So a HEAD response saying OK (200) is all that is required. Ryan,> format.xml is useless unless you want to return an XML file containing > whatever is being returned in the action. You dont need that line, or the > responds_to if you''re only going to have one thing it responds_to.Well yes, format.xml is useless unless you want to return XML for the action. But, as it turns out, returning XML for actions is VERY useful.> I don''t know why format.xml is included and if someone could inform us why, > that would be great :)You ask why, I ask why not? It is becoming more and more common for web applications to talk to each other. This is generally accomplished using XML to exchange data between applications. Having the scaffold generators include support for XML responses to RESTful actions is extremely useful. It allows the developer to create their REST API right along side their normal site development. Having this "baked-in" support for REST services goes a long way toward a standard where developers can begin to assume other applications support services in a conventional way. The basic idea here is that it''s time to stop assuming the requester is a web page (browser). There are a number of other ways to issues requests to a web application in this modern Web 2.0 era. HTML is certainly not the preferred response format for, say, terminal request via curl. In something like that you don''t want to sift through a bunch of HTML layout code to get to your data. XML is a great way to supply the data without the presentation. JSON is another great way to do that. Example: def show @forum = Forum.find(params[:id]) respond_to do |fomat| format.html # use the normal erb template to generate the HTML response format.iphone # use the erb template with optimized presentation for the iPhone format.xml { render :xml => @forum.to_xml } format.json { render :json => @forum.to_json } end end curl http://localhost:3000/forums/1.xml => XML response curl http://localhost:3000/forums/1.json => JSON response On Dec 6, 1:17 am, "Ryan Bigg" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> format.xml is useless unless you want to return an XML file containing > whatever is being returned in the action. You dont need that line, or the > responds_to if you''re only going to have one thing it responds_to. > > I don''t know why format.xml is included and if someone could inform us why, > that would be great :) > > On Dec 6, 2007 4:45 PM, sachin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <sachin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Hi all, > > > I am new to ROR world. I know the REST conceptually but find the > > difficulties in implementation can anybody guide me that which is the > > best book which i have to read. also some good links of implementation > > of rest in ROR. > > > If anybody made a small application to restful in rails please forward > > me that application. > > > i found some demo but i didn''t understand for what purpose they use > > format.xml > > > def update > > @forum.update_attributes!(params[:forum]) > > respond_to do |format| > > format.html { redirect_to @forum } > > format.xml { head 200 } > > end > > end > > > please help me i want to learn implementation of rest in ROR > > -- > Ryan Bigg--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---