Skip to content
This repository
Browse code

Add ability to delete posts.

  • Loading branch information...
commit ef16c97822cc50150a7d149ab3ec6e25a2c87a2b 1 parent e55f047
Hendrik Mans authored
1  CHANGES.md
Source Rendered
@@ -8,6 +8,7 @@ Upgrade Notes:
8 8
9 9 Changes:
10 10
  11 +* You can now delete posts you no longer need.
11 12 * The various available rake tasks have been moved to the `schnitzelpress` command line tool.
12 13 * Most of your blog's configuration is now stored in MongoDB and can be modified from the new "Configuration" page in your the admin panel.
13 14 * When logged in as an admin, you will be shown a small admin actions panel in the upper right corner of your browser, allowing you to quickly edit posts, jump to the admin section, or log out.
6 lib/schnitzelpress/actions/admin.rb
@@ -57,6 +57,12 @@ module Admin
57 57 haml :'admin/edit'
58 58 end
59 59 end
  60 +
  61 + delete '/admin/edit/:id/?' do
  62 + @post = Post.find(params[:id])
  63 + @post.destroy
  64 + redirect '/admin'
  65 + end
60 66 end
61 67 end
62 68 end
4 lib/schnitzelpress/helpers.rb
@@ -233,5 +233,9 @@ def link_to(title, target = "", options = {})
233 233 [:method, :confirm].each { |a| options[:data][a] = options.delete(a) }
234 234 haml "%a#{options} #{title}"
235 235 end
  236 +
  237 + def link_to_delete_post(title, post)
  238 + link_to title, "/admin/edit/#{post.id}", :method => :delete, :confirm => "Are you sure? This can not be undone."
  239 + end
236 240 end
237 241 end
4 lib/views/partials/_admin_post_list.haml
@@ -4,8 +4,8 @@
4 4 - posts.each do |post|
5 5 .row
6 6 .ten.columns
7   - %a{:href => post.to_url}= h (post.title || ("%s..." % post.body.first(50)))
  7 + %a{:href => "/admin/edit/#{post.id}"}= h (post.title || ("%s..." % post.body.first(50)))
8 8 .two.columns.icons
9 9 %a{:href => url_for(post)}= icon 'eye-open'
10 10 %a{:href => "/admin/edit/#{post.id}"}= icon 'edit'
11   - %a{:href => url_for(post)}= icon 'trash'
  11 + = link_to_delete_post icon('trash'), post
5 lib/views/partials/_post_form.haml
@@ -17,5 +17,6 @@
17 17 = form_field @post, :disqus
18 18
19 19 .buttons
20   - %button.green #{icon 'ok'} #{@post.new_record? ? 'Create Post' : 'Update Post'}
21   - %button.red #{icon 'trash'} Delete Post
  20 + %button.green{:type => 'submit'} #{icon 'ok'} #{@post.new_record? ? 'Create Post' : 'Update Post'}
  21 + or
  22 + = link_to_delete_post "delete this post", @post

0 comments on commit ef16c97

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