sharmano sharmano - 5 months ago 8
Ruby Question

Why are the comments not showing up in ruby on rails?

I made a ruby on rails blog as part of my project. I wanted to add comments to my blog. However, the site takes the comment and stores it successfully but when it comes to showing the comments, it doesn't work. I checked if the comment was registered using the rails console and it is registered. The github repository for it is : https://github.com/rocka0/blog-in-rails

Note: If specific code is needed, please let me know in the comments

Answer

https://github.com/rocka0/blog-in-rails/blob/master/app/views/posts/_comments.html.erb#L1

I think it should be:

<%= div_for @comments do |comment| %>

I'm a bit surprised it does not throw any error here.

Edit: You also don't set @comments instance variable anywhere in the controller: https://github.com/rocka0/blog-in-rails/blob/master/app/controllers/posts_controller.rb#L13 You should do it or use @post.comments instead.