From eb66eadfc627cbe6bfebdff7d5a1dfb01f00cd21 Mon Sep 17 00:00:00 2001 From: Mikhail Dieterle Date: Thu, 2 Aug 2012 20:02:37 +0300 Subject: fixed wrong route for creating new post [ci skip] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now there is error ```No route matches [POST] “/posts”``` --- guides/source/getting_started.textile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'guides/source/getting_started.textile') diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index 8d7c0d4bea..22da369a2a 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -373,7 +373,7 @@ Edit the +form_for+ line inside +app/views/posts/new.html.erb+ to look like this In this example, a +Hash+ object is passed to the +:url+ option. What Rails will do with this is that it will point the form to the +create+ action of the current controller, the +PostsController+, and will send a +POST+ request to that route. For this to work, you will need to add a route to +config/routes.rb+, right underneath the one for "posts/new": -post "posts/create" +post "posts" => "posts#create" By using the +post+ method rather than the +get+ method, Rails will define a route that will only respond to POST methods. The POST method is the typical method used by forms all over the web. @@ -1064,13 +1064,13 @@ received an error before. # rake routes - posts GET /posts(.:format) posts#index - posts_new GET /posts/new(.:format) posts#new -posts_create POST /posts/create(.:format) posts#create - GET /posts/:id(.:format) posts#show - GET /posts/:id/edit(.:format) posts#edit - PUT /posts/:id(.:format) posts#update - root / welcome#index + posts GET /posts(.:format) posts#index +posts_new GET /posts/new(.:format) posts#new + POST /posts(.:format) posts#create + GET /posts/:id(.:format) posts#show + GET /posts/:id/edit(.:format) posts#edit + PUT /posts/:id(.:format) posts#update + root / welcome#index To fix this, open +config/routes.rb+ and modify the +get "posts/:id"+ @@ -1175,7 +1175,7 @@ declaring separate routes with the appropriate verbs into get "posts" => "posts#index" get "posts/new" -post "posts/create" +post "posts" => "posts#create" get "posts/:id" => "posts#show", :as => :post get "posts/:id/edit" => "posts#edit" put "posts/:id" => "posts#update" -- cgit v1.2.3