Ruby on Rails
Saturday, April 2, 2011
I have a question about the design decision behind the rails default routing.
The normal routing is, to create a new record we GET `/things/new`. However, when the user submits a new thing he is posting to #create at `/things`. The vanilla create action looks like:
def create
@thing = Thing.new(params[:thing])
if @thing.save
redirect_to(@thing), :notice => "Thing created!"
else
render 'new'
end
end
Hence, if validation fails, the user is presented with the form view he just saw at `/things/new`, but now the URL he sees is `/things`.
Now, this really bothers me for two main reasons:
1. Showing the invalid record at `/things` is making a GET request on things, but GET `/things` belongs #index.
2. Because the URL does not match the view the user is seeing, if the user hits reload he loses his form and gets the index.
What I'd like to know is, what is the rational behind this routing setup? Why shouldn't the #create action be routed to receive POST requests at `/things/new` instead of `/things`.
I know that tons of time, energy, and careful decision-making has gone into making rails - and I love the framework - but I would feel a lot better if I understood the logic behind this decision. From an end-user-experience point-of-view this seems quite confusing to 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@googlegroups.com.
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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment