maven apache
2012-Apr-08 11:57 UTC
how does rails differentiate the method for the same url
Hi: This is a cross post at stackoverflow<http://stackoverflow.com/questions/10059550/how-does-rails-differentiate-the-method-for-the-same-url>, since I do not get the preferred answer,so I post to this list. ------------------------------------------------------------------------------------- I am new in rails,and I create the first rails application (Blog) follow the guide at rails''s docs<http://guides.rubyonrails.org/getting_started.html>step by step. However when I run the application,I found something I can not understand. http://localhost:3000/posts/2 With GET method,this will return the details of post whose id is 2. But when update this post,I found the action of the form is ''/posts/2''. When delete the post,I found rails create a form element in the body with action ''/posts/2'' and method POST,so I wonder how does rails know update or delete this post? Since I do not found any condition word in the post controller. But for path /posts/2,the verbs is POST,both the path and verb are the same. How does rails know to delete or update the post 2? Hope some one can help me. Thanks. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2012-Apr-09 18:11 UTC
Re: how does rails differentiate the method for the same url
On Apr 8, 12:57 pm, maven apache <apachemav...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi: > > This is a cross post at > stackoverflow<http://stackoverflow.com/questions/10059550/how-does-rails-differenti...>, > since I do not get the preferred answer,so I post to this list. > > --------------------------------------------------------------------------- ---------- > > I am new in rails,and I create the first rails application (Blog) follow > the guide at rails''s > docs<http://guides.rubyonrails.org/getting_started.html>step by step. > > However when I run the application,I found something I can not understand. > > http://localhost:3000/posts/2 > > With GET method,this will return the details of post whose id is 2. > > But when update this post,I found the action of the form is ''/posts/2''. > > When delete the post,I found rails create a form element in the body with > action ''/posts/2'' and method POST,so I wonder how does rails know update or > delete this post? > > Since I do not found any condition word in the post controller. > But for path /posts/2,the verbs is POST,both the path and verb are the > same. How does rails know to delete or update the post 2?Because browsers don''t commonly support methods such as PUT, DELETE etc. these are emulated by having a hidden field in the form called _method. The rails routing engine extracts this and uses this overridden method to route the request Fred> > Hope some one can help me. > > Thanks.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.