You could append the form to the page using JS & Ajax, like this:
#config/routes.rb
resources :posts do
resources :comments
end
#app/assets/javascripts/application.js
$(document).on("click", "a.new_comment", function() {#
id = $(this).attr("id");
$.ajax({
url: $(this).attr("href");
success: function(data) {
$("#" + id).append(data);
}
});
});
#app/views/posts/index.html.erb
<% @posts.each do |post| %>
<%= post.title %>
<%= link_to "Add Comment", new_post_comment_path(post.id), class: "new_comment", id: post.id %>
<% end %>
#app/controllers/comments_controller.rb
def new
@comment = Comment.new
respond_to do |format|
format.html { render layout: !request.xhr? }
end
end