Hey there! I've been diving into working with Rails recently and have been experimenting with making Ajax requests when submitting forms for comments. The goal is to have the results appended to the list of comments seamlessly. Thanks to this helpful video tutorial, I managed to get it working: https://www.youtube.com/watch?v=K-sns5tNdTY.
Afterwards, I decided to take it a step further by adding answers to my comments. This involved implementing a new model and creating buttons using CoffeeScript within each comment to display the answers along with a form for new answers (initially hidden using CSS). It was quite challenging, but I eventually got it all up and running smoothly.
However, I've run into a snag. When adding a new comment, the "Responder" button on the added comment ends up refreshing the page instead of functioning as intended (showing the hidden section). Here's how I'm rendering the comments and the form:
<div id="comment-section" class="border-element-sm-div" style="overflow: hidden">
<h3 style="width: 500px">Comments</h3>
<div id="comments">
<%= render @comments %>
</div>
<% if @comments.count <= 0 %>
<p style="font-style: italic; color: grey; margin-left: 10px">No comments yet. Be the first one to comment!</p>
<% end %>
<% if user_signed_in? %>
<div style="overflow: auto">
<%= render :partial => 'comments/form' %>
</div>
<% end %>
</div>
This is just a preview of what I'm grappling with in the realm of Rails development. If you have any insights or suggestions, I'd greatly appreciate your input! Thank you.