2011-12-19 15:30:14 +00:00
|
|
|
class CommentsController < ApplicationController
|
|
|
|
before_filter :authenticate_user!
|
2011-12-20 10:20:00 +00:00
|
|
|
before_filter :set_commentable, :only => [:index, :edit, :create]
|
2011-12-21 14:48:16 +00:00
|
|
|
before_filter :find_project, :only => [:index]
|
|
|
|
before_filter :find_comment, :only => [:show, :edit, :update, :destroy]
|
|
|
|
|
|
|
|
authorize_resource :only => [:show, :edit, :update, :destroy]
|
|
|
|
authorize_resource :project, :only => [:index]
|
2011-12-19 15:30:14 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
@comments = @commentable.comments
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@comment = @commentable.comments.build(params[:comment])
|
2011-12-20 10:20:00 +00:00
|
|
|
@comment.user = current_user
|
2011-12-19 15:30:14 +00:00
|
|
|
if @comment.save
|
|
|
|
flash[:notice] = I18n.t("flash.comment.saved")
|
2011-12-20 10:20:00 +00:00
|
|
|
redirect_to :back
|
2011-12-19 15:30:14 +00:00
|
|
|
else
|
|
|
|
flash[:error] = I18n.t("flash.comment.saved_error")
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-20 10:20:00 +00:00
|
|
|
def edit
|
|
|
|
@issue = @commentable
|
|
|
|
@project = @issue.project
|
|
|
|
end
|
|
|
|
|
2011-12-19 15:30:14 +00:00
|
|
|
def update
|
|
|
|
if @comment.update_attributes(params[:comment])
|
|
|
|
flash[:notice] = I18n.t("flash.comment.saved")
|
2011-12-22 07:41:37 +00:00
|
|
|
#redirect_to :back
|
|
|
|
redirect_to show_issue_path(@comment.commentable.project, @comment.commentable.serial_id)
|
2011-12-19 15:30:14 +00:00
|
|
|
else
|
|
|
|
flash[:error] = I18n.t("flash.comment.saved_error")
|
|
|
|
render :action => 'new'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@comment.destroy
|
|
|
|
|
|
|
|
flash[:notice] = t("flash.comment.destroyed")
|
2011-12-20 10:20:00 +00:00
|
|
|
redirect_to :back
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_commentable
|
2011-12-21 14:48:16 +00:00
|
|
|
#params.each do |name, value|
|
|
|
|
# if name =~ /(.+)_id$/
|
|
|
|
# return $1.classify.constantize.find(value)
|
|
|
|
# end
|
|
|
|
#end
|
|
|
|
#nil
|
|
|
|
return Issue.find(params[:issue_id])
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|
2011-12-20 10:20:00 +00:00
|
|
|
|
|
|
|
def set_commentable
|
|
|
|
@commentable = find_commentable
|
|
|
|
end
|
2011-12-21 14:48:16 +00:00
|
|
|
|
|
|
|
def find_comment
|
|
|
|
@comment = Comment.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_project
|
|
|
|
@project = @comment.commentable.project
|
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|