2014-03-23 00:22:25 +00:00
|
|
|
class CommentsController < ApplicationController
|
2014-04-12 01:35:42 +00:00
|
|
|
before_filter :get_comment, only: [:raw, :quote, :edit, :update, :destroy]
|
2014-03-23 00:22:25 +00:00
|
|
|
respond_to :html, :js
|
|
|
|
|
|
|
|
def index
|
|
|
|
@comments = Comment.recent.filtered
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2014-04-13 11:16:51 +00:00
|
|
|
@comments = Comment.recent5.all conditions: { commentable_id: params[:id2], commentable_type: params[:id] }
|
2014-03-31 21:33:16 +00:00
|
|
|
render partial: 'list', layout: false
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
raise AccessError unless @comment.can_update? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@comment = Comment.new params[:comment]
|
|
|
|
@comment.user = cuser
|
|
|
|
raise AccessError unless @comment.can_create? cuser
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @comment.save
|
|
|
|
flash[:notice] = t(:comments_create)
|
2014-03-31 21:33:16 +00:00
|
|
|
format.js { render }
|
2014-03-23 00:22:25 +00:00
|
|
|
else
|
|
|
|
flash[:error] = t(:comments_invalid) + @comment.errors.full_messages.to_s
|
|
|
|
format.html { redirect_to(:back)}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
raise AccessError unless @comment.can_update? cuser
|
|
|
|
if @comment.update_attributes params[:comment]
|
|
|
|
flash[:notice] = t(:comments_update)
|
|
|
|
return_to
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :edit
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
raise AccessError unless @comment.can_destroy? cuser
|
|
|
|
@comment.destroy
|
|
|
|
redirect_to_back
|
|
|
|
end
|
|
|
|
|
2014-04-12 01:35:42 +00:00
|
|
|
def quote
|
|
|
|
end
|
|
|
|
|
2014-03-23 00:22:25 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def get_comment
|
|
|
|
@comment = Comment.find params[:id]
|
|
|
|
end
|
|
|
|
end
|