diff options
Diffstat (limited to 'guides/code/getting_started')
3 files changed, 10 insertions, 0 deletions
diff --git a/guides/code/getting_started/app/controllers/posts_controller.rb b/guides/code/getting_started/app/controllers/posts_controller.rb index fc71e9b4e8..85d2c1de47 100644 --- a/guides/code/getting_started/app/controllers/posts_controller.rb +++ b/guides/code/getting_started/app/controllers/posts_controller.rb @@ -35,4 +35,11 @@ class PostsController < ApplicationController render 'edit' end end + + def destroy + @post = Post.find(params[:id]) + @post.destroy + + redirect_to :action => :index + end end diff --git a/guides/code/getting_started/app/views/posts/index.html.erb b/guides/code/getting_started/app/views/posts/index.html.erb index 3ba7091c15..7b72720d50 100644 --- a/guides/code/getting_started/app/views/posts/index.html.erb +++ b/guides/code/getting_started/app/views/posts/index.html.erb @@ -8,6 +8,7 @@ <th>Text</th> <th></th> <th></th> + <th></th> </tr> <% @posts.each do |post| %> @@ -16,6 +17,7 @@ <td><%= post.text %></td> <td><%= link_to 'Show', :action => :show, :id => post.id %> <td><%= link_to 'Edit', :action => :edit, :id => post.id %> + <td><%= link_to 'Destroy', { :action => :destroy, :id => post.id }, :method => :delete, :confirm => 'Are you sure?' %> </tr> <% end %> </table> diff --git a/guides/code/getting_started/config/routes.rb b/guides/code/getting_started/config/routes.rb index 02ca24e95a..6095a05a58 100644 --- a/guides/code/getting_started/config/routes.rb +++ b/guides/code/getting_started/config/routes.rb @@ -9,6 +9,7 @@ Blog::Application.routes.draw do get "posts/:id" => "posts#show", :as => :post get "posts/:id/edit" => "posts#edit" put "posts/:id" => "posts#update" + delete "posts/:id" => "posts#destroy" # The priority is based upon order of creation: # first created -> highest priority. |