DEV Community

How to create a comment and reply system in Ruby on Rails

James Garcia on October 30, 2020

This is a tutorial about building a simple comment and reply system with Ruby on Rails. I was looking for a way to build this without a gem. Most t...
Collapse
 
wcurzor profile image
Weltone Curzor

hello such great idea but i got the problem below with some part of your code

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
godfreymutebi profile image
Mutebi Godfrey

ee

Thread Thread
 
godfreymutebi profile image
Mutebi Godfrey

m

Thread Thread
 
godfreymutebi profile image
Mutebi Godfrey

mm

Collapse
 
Sloan, the sloth mascot
Comment deleted
 
godfreymutebi profile image
Mutebi Godfrey

l

Thread Thread
 
godfreymutebi profile image
Mutebi Godfrey

l

Collapse
 
wcurzor profile image
Weltone Curzor

these particular problem is just when i hit the reply link

NoMethodError in Comments#new
Showing E:/Projects/app/app/views/comments/_form.html.erb where line #1 raised:

undefined method `comments_path' for #ActionView::Base:0x00000000026a70

Did you mean? font_path

Extracted source (around line #1):

<%= form_with(model: comment, local: true) do |form| %>

<% if comment.errors.any? %>



<%= pluralize(comment.errors.count, "error") %> prohibited this comment from being saved:

  <ul>
Collapse
 
jamgar profile image
James Garcia

@wcurzor my suggestion is to start looking over the Replies section of the article to see if you have everything as the article. One thing to check if you have the remote: true set in the file below. That would be the only "gotcha" that I can see.

# app/views/comments/_comment.html.erb
      <%= comment.body %>
      <%= link_to 'reply', new_post_comment_path(@post, parent_id: comment.id), remote: true, class: 'd-block' %>
      </div>
Enter fullscreen mode Exit fullscreen mode

Here is the completed app.

Collapse
 
jamgar profile image
James Garcia

Thank you @wcurzor As for the error, I will look into it.

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
hurabafzal2 profile image
hurabafzal2

i wanted to convert whole system to ajax firstly the comment field is not getting empty after reply and the replies to comments are not showing on the page at first but when i refresh the page they are shown

Collapse
 
godfreymutebi profile image
Mutebi Godfrey

any idea on how to reply the reply button with a form using turbo_frames in rails rails 7

Collapse
 
jamgar profile image
James Garcia

I will need to revise this post to use turbo. Sorry don’t have the answer right now.

Collapse
 
godfreymutebi profile image
Mutebi Godfrey

recent