refactors comments controller ugly method

This commit is contained in:
Juanjo Bazán
2015-08-24 18:59:53 +02:00
parent 030fd49120
commit 82fb56e4c0

View File

@@ -44,9 +44,9 @@ class CommentsController < ApplicationController
end end
def check_for_special_comments def check_for_special_comments
if ["1", true].include?(comment_params[:as_administrator]) && can?(:comment_as_administrator, debate) if administrator_comment?
@comment.administrator_id = current_user.administrator.id @comment.administrator_id = current_user.administrator.id
elsif ["1", true].include?(comment_params[:as_moderator]) && can?(:comment_as_moderator, debate) elsif moderator_comment?
@comment.moderator_id = current_user.moderator.id @comment.moderator_id = current_user.moderator.id
end end
end end
@@ -71,4 +71,12 @@ class CommentsController < ApplicationController
reply? && parent.author.email_on_comment_reply? reply? && parent.author.email_on_comment_reply?
end end
def administrator_comment?
["1", true].include?(comment_params[:as_administrator]) && can?(:comment_as_administrator, Debate)
end
def moderator_comment?
["1", true].include?(comment_params[:as_moderator]) && can?(:comment_as_moderator, Debate)
end
end end