Class: Polemic::CommentsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- BaseController
- Polemic::CommentsController
- Defined in:
- app/controllers/polemic/comments_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/controllers/polemic/comments_controller.rb', line 4 def create @comment = Comment.new(params[:comment]) @comment.user = current_user if @comment.save respond_to do |format| format.html { redirect_to :back, :notice => I18n.t("polemic.comment.added") } end else respond_to do |format| format.html { redirect_to :back, :notice => I18n.t("polemic.comment.has_errors") } end end end |
#destroy ⇒ Object
def index
@comments = Comment.where(:commentable_id => params[:commentable_id], :commentable_type => params[:commentable_type])
respond_to do |format|
format.json { render :json => @comments }
format.html {
render @comments #:partial => "comments/index", :locals => { :comments => @post.comments.includes(:user, :post) }
}
end
end
28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/polemic/comments_controller.rb', line 28 def destroy @comment = Comment.find(params[:id]) if @comment.has_children? # if comment has children, mark as deleted @comment.mark_as_deleted! else @comment.destroy # if no children, destroy it! end redirect_to :back, :notice => I18n.t("polemic.comment.removed") end |