Allow undeleting comments
This commit is contained in:
@@ -62,6 +62,15 @@ class CommentsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def undelete
|
||||
@comment = Comment.find(params[:id])
|
||||
check_privilege(@comment)
|
||||
@comment.undelete!
|
||||
respond_with(@comment) do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def unvote
|
||||
@comment = Comment.find(params[:id])
|
||||
@comment.unvote!
|
||||
|
||||
@@ -9,7 +9,7 @@ class Comment < ActiveRecord::Base
|
||||
before_validation :initialize_updater
|
||||
after_create :update_last_commented_at_on_create
|
||||
after_destroy :update_last_commented_at_on_destroy
|
||||
attr_accessible :body, :post_id, :do_not_bump_post
|
||||
attr_accessible :body, :post_id, :do_not_bump_post, :is_deleted
|
||||
|
||||
module SearchMethods
|
||||
def recent
|
||||
@@ -175,6 +175,10 @@ class Comment < ActiveRecord::Base
|
||||
def delete!
|
||||
update_attributes(:is_deleted => true)
|
||||
end
|
||||
|
||||
def undelete!
|
||||
update_attributes(:is_deleted => false)
|
||||
end
|
||||
end
|
||||
|
||||
Comment.connection.extend(PostgresExtensions)
|
||||
|
||||
@@ -25,7 +25,11 @@
|
||||
<% if @post || @posts %>
|
||||
<li><%= link_to "Reply", new_comment_path(:post_id => comment.post_id), :class => "reply-link", "data-comment-id" => comment.id %></li>
|
||||
<% if comment.editable_by?(CurrentUser.user) %>
|
||||
<li><%= link_to "Delete", comment_path(comment.id), :data => {:confirm => "Are you sure you want to delete this comment?"}, :method => :delete, :remote => true %></li>
|
||||
<% if comment.is_deleted? %>
|
||||
<li><%= link_to "Undelete", undelete_comment_path(comment.id), :method => :post, :remote => true %></li>
|
||||
<% else %>
|
||||
<li><%= link_to "Delete", comment_path(comment.id), :data => {:confirm => "Are you sure you want to delete this comment?"}, :method => :delete, :remote => true %></li>
|
||||
<% end %>
|
||||
<li><%= link_to "Edit", edit_comment_path(comment.id), :id => "edit_comment_link_#{comment.id}", :class => "edit_comment_link" %></li>
|
||||
<% end %>
|
||||
<li id="comment-vote-up-link-for-<%= comment.id %>"><%= link_to "Vote up", comment_votes_path(:comment_id => comment.id, :score => "up"), :method => :post, :remote => true %></li>
|
||||
|
||||
1
app/views/comments/undelete.js.erb
Normal file
1
app/views/comments/undelete.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
location.reload();
|
||||
@@ -96,6 +96,7 @@ Rails.application.routes.draw do
|
||||
end
|
||||
member do
|
||||
put :unvote
|
||||
post :undelete
|
||||
end
|
||||
end
|
||||
resources :counts do
|
||||
|
||||
Reference in New Issue
Block a user