So I decided to make a blog in RoR and all is good I got the comments to submit and what not but when I went to "update" the submit method to allow for the page not to be refreshed when the comment is posted (ajax) however now whenever I go to post a comment on the pages for some reason it loops the send from the comment submit and I get two comments with the same message appearing at the same time.
<h2>Comments</h2>
<div id="comments">
<%= render :partial => @post.comments %>
</div>
<%= form_for [@post, Comment.new], :remote => true do |f| %>
<p>
<%= f.label :body, "New comment" %><br/>
<%= f.text_area :body %>
</p>
<p><%= f.submit "Add comment", disable_with: "Adding Comment..." %></p>
<% end %>
That is the show point, as you can see I tried to see if disabling the button with disable_with would help but it has not.
and below is the comment_controller
class CommentsController < ApplicationController
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create!(comment_params)
respond_to do |format|
format.html { redirect_to @post }
format.js
end
end
private
def comment_params
params.require(:comment).permit(:commenter, :body, :post_id)
end
end
Thanks for any advice.
Looks like you have two sets of precompiled assets running locally:.
Try this on your machine:
RAILS_ENV=development bundle exec rake assets:clobber
RAILS_ENV=development bundle exec rake assets:precompile
Happens to me all the time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.