diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index b6d066935..14dabf49c 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -1,11 +1,11 @@ module CommentsHelper - def comment_link_text(parent) - parent.is_a? Comment ? t("comments_helper.reply_link") : t("comments_helper.comment_link") + def comment_link_text(parent_id) + parent_id.present? ? t("comments_helper.reply_link") : t("comments_helper.comment_link") end - def comment_button_text(parent) - parent.is_a? Comment ? t("comments_helper.reply_button") : t("comments_helper.comment_button") + def comment_button_text(parent_id) + parent_id.present? ? t("comments_helper.reply_button") : t("comments_helper.comment_button") end end \ No newline at end of file diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index e21b148bc..e02cb4c48 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -88,14 +88,14 @@ <%= render 'comments/actions', comment: comment %> - <%= render 'comments/form', {parent: comment, toggeable: true} %> + <%= render 'comments/form', {commentable: @debate, parent_id: comment.id, toggeable: true} %> <% end %> <% end %>
- <%= render comment.children.for_render.reorder('id DESC, lft') %> + <%= render comment.children.for_render.reorder('id DESC') %>
diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index 71735eaaa..70e600df0 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -1,22 +1,23 @@ -
> - <%= form_for [@debate, Comment.new], remote: true do |f| %> - <%= label_tag "comment-body-#{dom_id(parent)}", t("comments.form.leave_comment") %> - <%= f.text_area :body, id: "comment-body-#{dom_id(parent)}", label: false %> - <%= f.hidden_field :commentable_type, value: parent.class %> - <%= f.hidden_field :commentable_id, value: parent.id %> +
> + <%= form_for [commentable, Comment.new], remote: true do |f| %> + <%= label_tag "comment-body-#{dom_id(commentable)}", t("comments.form.leave_comment") %> + <%= f.text_area :body, id: "comment-body-#{dom_id(commentable)}", label: false %> + <%= f.hidden_field :commentable_type, value: commentable.class %> + <%= f.hidden_field :commentable_id, value: commentable.id %> + <%= f.hidden_field :parent_id, value: parent_id %> - <%= f.submit comment_button_text(parent), class: "button radius small inline-block" %> + <%= f.submit comment_button_text(parent_id), class: "button radius small inline-block" %> - <% if can? :comment_as_moderator, @debate %> + <% if can? :comment_as_moderator, commentable %>ยบ
- <%= f.check_box :as_moderator, id: "comment-as-moderator-#{dom_id(parent)}", label: false %> - <%= label_tag "comment-as-moderator-#{dom_id(parent)}", t("comments.form.comment_as_moderator"), class: "checkbox" %> + <%= f.check_box :as_moderator, id: "comment-as-moderator-#{dom_id(commentable)}", label: false %> + <%= label_tag "comment-as-moderator-#{dom_id(commentable)}", t("comments.form.comment_as_moderator"), class: "checkbox" %>
<% end %> - <% if can? :comment_as_administrator, @debate %> + <% if can? :comment_as_administrator, commentable %>
- <%= f.check_box :as_administrator, id: "comment-as-administrator-#{dom_id(parent)}",label: false %> - <%= label_tag "comment-as-administrator-#{dom_id(parent)}", t("comments.form.comment_as_admin"), class: "checkbox" %> + <%= f.check_box :as_administrator, id: "comment-as-administrator-#{dom_id(commentable)}",label: false %> + <%= label_tag "comment-as-administrator-#{dom_id(commentable)}", t("comments.form.comment_as_admin"), class: "checkbox" %>
<% end %> <% end %> diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 8fab71128..d5bce5bef 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -82,7 +82,7 @@ (<%= @debate.comments_count %>) <% if user_signed_in? %> - <%= render 'comments/form', {parent: @debate, toggeable: false} %> + <%= render 'comments/form', {commentable: @debate, parent_id: nil, toggeable: false} %> <% else %>