diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 5fbcbae..385d591 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -26,11 +26,7 @@ def create comment.user = current_user if comment.save - if comment.parent_id.present? - redirect_to article_comment_path(article, comment.parent_id) - else - redirect_to article - end + redirect_to article else render "articles/show", status: :unprocessable_entity end diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index 9f7fe15..425dff6 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -1,30 +1,40 @@ module CommentsHelper def render_comment_tree(comment) - content_tag :li do - concat content_tag(:p, comment.text) - concat content_tag(:div, class: "subtext", style: "display: flex; align-items: center;") { - safe_concat button_to("Upvote", upvote_article_comment_path(comment.article, comment), method: :post, class: "btn btn-sm upvote-button", data: {votable_type: "Comment", votable_id: comment.id, article_id: comment.article.id}) - safe_concat button_to("Downvote", downvote_article_comment_path(comment.article, comment), method: :post, class: "btn btn-sm downvote-button", data: {votable_type: "Comment", votable_id: comment.id, article_id: comment.article.id}) - - # concat button_to(upvote_article_comment_path(comment), method: :post, class: "btn btn-sm upvote-button", data: {votable_type: "Comment", votable_id: comment.id, article_id: comment.article.id}) do - # content_tag(:i, "", class: "fas fa-arrow-up") - # end - # concat button_to(downvote_article_comment_path(comment), method: :post, class: "btn btn-sm downvote-button", data: {votable_type: "Comment", votable_id: comment.id, article_id: comment.article.id}) do - # content_tag(:i, "", class: "fas fa-arrow-down") - # end - - safe_concat content_tag(:span, "#{comment.score} points", id: "score-Comment-#{comment.id}", class: "score") - concat raw(" ") - safe_concat "by" - concat raw(" ") - safe_concat link_to(comment.user.name, comment.user) - concat raw(" ") - safe_concat "on #{comment.created_at.strftime("%B %d, %Y at %I:%M %p")}" - safe_concat " | " - safe_concat link_to(" reply", article_comment_path(comment.article, comment)) - } + content_tag :div do + concat content_tag(:table, border: "0", cellpadding: "0", cellspacing: "0") { + concat content_tag(:tbody) { + concat content_tag(:tr) { + concat content_tag(:td, valign: "top", class: "votelinks") { + content_tag(:center) { + concat button_to(upvote_article_comment_path(comment), method: :post, class: "btn btn-sm upvote-button", data: { votable_type: 'Comment', votable_id: comment.id, article_id: comment.article.id }) { + content_tag(:i, '', class: "fas fa-arrow-up") + } + concat button_to(downvote_article_comment_path(comment), method: :post, class: "btn btn-sm downvote-button", data: { votable_type: 'Comment', votable_id: comment.id, article_id: comment.article.id }) { + content_tag(:i, '', class: "fas fa-arrow-down") + } + } + } + concat content_tag(:td, comment.text, valign: "top", style: "padding-left: 10px;") + } + concat content_tag(:tr) { + concat content_tag(:td, '', colspan: "2") + concat content_tag(:td, class: "subtext") { + safe_concat content_tag(:span, "#{comment.score} points", id: "score-Comment-#{comment.id}", class: "score") + concat raw(" ") + safe_concat "by" + concat raw(" ") + safe_concat link_to(comment.user.name, comment.user) + concat raw(" ") + safe_concat content_tag(:span, "on #{comment.created_at.strftime("%B %d, %Y at %I:%M %p")}") + safe_concat " | " + safe_concat link_to(" reply", article_comment_path(comment.article, comment)) + } + } + concat content_tag(:tr, '', style: "height:5px") + } + } if comment.replies.any? - concat(content_tag(:ul) do + concat(content_tag(:ul, style: "list-style-type: none; padding-left: 20px;") do comment.replies.each do |reply| concat render_comment_tree(reply) end @@ -33,3 +43,4 @@ def render_comment_tree(comment) end end end + diff --git a/app/views/comments/show.html.erb b/app/views/comments/show.html.erb index d1b0ad9..7e4f1a5 100644 --- a/app/views/comments/show.html.erb +++ b/app/views/comments/show.html.erb @@ -17,7 +17,7 @@ <% end %> - + <%= comment.text %> diff --git a/db/seeds.rb b/db/seeds.rb index aae96e4..f4d877c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -43,9 +43,9 @@ comments = Comment.all replies = [] # Create replies to comments -comments.each do |comment| +comments.each_with_index do |comment, i| replies << Comment.create!( - text: "Sample Reply", + text: "Sample Reply #{i+1}", article: comment.article, user: users.sample, parent_id: comment.id @@ -53,9 +53,9 @@ end # replies to replies -replies.each do |reply| +replies.each_with_index do |reply, i| Comment.create!( - text: "Sample Reply", + text: "Sample Reply to Reply #{i+1}", article: reply.article, user: users.sample, parent_id: reply.id