I am fairly new to Rails and I am trying to understand the default routes generated by resources in routes.rb Is there a justification for having the default route generated by resources for create as "/things" POST /things(.:format) {:action=>"create", :controller=>"things"} Wouldn''t it be a better idea to have something like create_things POST /things/new(.:format) {:action=>"create", :controller=>"things"} I came across a scenario where this seems to be a problem. 1. User fills in a form at /things/new 2. Submits the form with invalid form fields. 3. render "new" is called from create action to display the error messages. 4. new form is rendered but because of create action being mapped to /things, the URL now points to /things. 5. This is confusing for the user as he expects to go to index page by this URL. But here the URL points to /things and it has the new form. 6. Wouldn''t it be a better interface for the user if we have default POST /things/new for create, which will take keep the user on the same URL /things/new when invalid form is submitted. I was curious about why do we have the default route for create as /things. Is there a use-case that I am missing ? - Harshal -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/ixbl-bto5J4J. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
From a REST perspective, the URL is 100% irrelevant. I havent tested it with analytics or anything, I''m pretty sure that the number of people who go "oh, my form failed. I''d better see what the URL is. Oh, /things!'' How odd? I expect that to be a list?? What''s going on???'' is zero. /things works because it''s both the list of things and where you send data to make a new thing in the list. From RFC2616: http://tools.ietf.org/html/rfc2616.html#section-9.5> The POST method is used to request that the origin server accept the > entity enclosed in the request *as a new subordinate of the resource* > identified by the Request-URI in the Request-Line.Emphasis mine. It is arguable that /things/1 is not subordinate to /things/new, and therefore, it''s better to POST to /things. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Hey Steve, Thanks for clearing that up. Need to spend more time referring to RFC docs. Glad you pointed me in that direction. - Harshal On Thu, Aug 9, 2012 at 10:14 AM, Steve Klabnik <steve@steveklabnik.com>wrote:> From a REST perspective, the URL is 100% irrelevant. > > I havent tested it with analytics or anything, I''m pretty sure that > the number of people who go "oh, my form failed. I''d better see what > the URL is. Oh, /things!'' How odd? I expect that to be a list?? What''s > going on???'' is zero. > > /things works because it''s both the list of things and where you send > data to make a new thing in the list. From RFC2616: > http://tools.ietf.org/html/rfc2616.html#section-9.5 > > > The POST method is used to request that the origin server accept the > > entity enclosed in the request *as a new subordinate of the resource* > > identified by the Request-URI in the Request-Line. > > Emphasis mine. It is arguable that /things/1 is not subordinate to > /things/new, and therefore, it''s better to POST to /things. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
> Thanks for clearing that up. Need to spend more time referring to RFC docs. > Glad you pointed me in that direction.Any time. :) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.