From f4447607f20c420d9c341b19064c07d5b7aa6cee Mon Sep 17 00:00:00 2001 From: Oscar Del Ben Date: Fri, 27 Apr 2012 14:21:02 +0200 Subject: Add delete post section to Getting Started guide --- guides/code/getting_started/app/controllers/posts_controller.rb | 7 +++++++ guides/code/getting_started/app/views/posts/index.html.erb | 2 ++ 2 files changed, 9 insertions(+) (limited to 'guides/code/getting_started/app') 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 @@ Text + <% @posts.each do |post| %> @@ -16,6 +17,7 @@ <%= post.text %> <%= link_to 'Show', :action => :show, :id => post.id %> <%= link_to 'Edit', :action => :edit, :id => post.id %> + <%= link_to 'Destroy', { :action => :destroy, :id => post.id }, :method => :delete, :confirm => 'Are you sure?' %> <% end %> -- cgit v1.2.3