Skip to content
Browse files

added delete action / template

  • Loading branch information...
1 parent 49b1047 commit 18717db00e4b8d8ad836885c85c55690067c250c @hukl committed Apr 5, 2010
Showing with 24 additions and 4 deletions.
  1. +17 −4 lib/admin.rb
  2. +6 −0 views/admin/delete.erb
  3. +1 −0 views/admin/index.erb
View
21 lib/admin.rb
@@ -2,6 +2,8 @@ module Admin
class App < Sinatra::Base
+ set :method_override, true
+
before do
redirect '/account/login' unless env['warden'].user
end
@@ -25,13 +27,24 @@ class App < Sinatra::Base
end
end
- get '/posts/:id/edit' do
- @post = Post.find(params[:id])
+ get '/posts/:id/edit/?' do
+ @post = Post.find( params[:id] )
erb :'admin/edit', :layout => :'admin/layout'
end
- post '/posts/:id/?' do
- @post = Post.find(params[:id])
+ get '/posts/:id/delete/?' do
+ @post = Post.find( params[:id] )
+ erb :'admin/delete'
+ end
+
+ delete '/posts/:id' do
+ post = Post.find( params[:id] )
+ post.delete #if post
+ post.inspect
+ end
+
+ put '/posts/:id/?' do
+ @post = Post.find( params[:id] )
if @post.update_attributes( params[:post] )
redirect '/admin/'
View
6 views/admin/delete.erb
@@ -0,0 +1,6 @@
+<h3>Do you really want to delete this post?</h3>
+
+<form method="post" action="/admin/posts/<%= @post.id %>">
+ <input name="_method" value="delete" type="hidden" />
+ <input type="submit" value="Delete" />
+</form>
View
1 views/admin/index.erb
@@ -10,6 +10,7 @@
<td><%= Time.now.to_s(:db) %></td>
<td>
<a href="/admin/posts/<%= post.id %>/edit">Edit</a>
+ <a href="/admin/posts/<%= post.id %>/delete">Delete</a>
</td>
</tr>
<% end %>

0 comments on commit 18717db

Please sign in to comment.
Something went wrong with that request. Please try again.