Reputation: 797
I have controller ArticlesController.
I have resource articles (in routes.rb file).
Why action articles#new
corresponds GET /articles/new
request and action acticles#create
corresponds POST /articles
request. Why not POST /articles/new
?
Upvotes: 0
Views: 54
Reputation: 1302
It's defined in the RESTful architecture that a POST request to a collection URI (e.g. "/articles") should create a new entry.
As already noted, the "/articles/new" URI is simply displaying the form, and it's not really an element URI (in the RESTful sense). Therefore it would be inproper to POST, PUT or DELETE it.
See http://en.wikipedia.org/wiki/Representational_state_transfer
Upvotes: 1
Reputation: 4053
The new
action displays a view in which you have a form that you fill out and submit. In this case, its a form for articles
. This form could be anywhere on your website, but Rails convention holds that it is in your new
page.
The create
action takes the information you submitted in the form and tries to create an object. In this case, an article
. This action does not, by convention, display a view, but redirects to another page. For me, it's usually the show
page of that newly created article
.
Upvotes: 1