Ruby On Rails Ajax 提交提交两次
Ruby On Rails Ajax Submit submitting twice
所以我决定在 RoR 中制作一个博客,一切都很好,我收到了要提交的评论,但当我去"更新"提交方法以允许在发布评论时不刷新页面(ajax)但是现在每当我出于某种原因在页面上发表评论时,它都会循环从评论提交发送,我得到两条评论同时出现相同的消息。
<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 %>
这就是显示点,如您所见,我试图查看禁用disable_with按钮是否有帮助,但没有。
下面是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
感谢您的任何建议。
看起来您有两组预编译资产在本地运行:
在您的计算机上尝试此操作:
RAILS_ENV=development bundle exec rake assets:clobber
RAILS_ENV=development bundle exec rake assets:precompile
一直发生在我身上。
相关文章:
- HTML/JS表单已提交两次
- Ruby On Rails Ajax 提交提交两次
- 联系表格提交两次
- Ajax Post-Submit函数提交两次
- 使用Foundation Abide提交两次表格
- MVC3 AJAX将数据传递给控制器.它's已提交两次
- jQuery表单验证器:需要提交两次
- Ajax表单提交两次
- 聚合物铁形式,在输入时提交两次
- 使用 jquery.form.js jquery 插件导致我的表单提交两次
- 在发送更新数据之前,表格需要提交两次
- 我们可以提交两次 jsp 表单吗?
- Ajax 表单使用 Yii 2 提交两次
- 角度表单提交两次(ajax get request)
- 带有jQuery提交运行的Javascript表单运行提交两次
- Cakephp表单必须提交两次才能工作
- 在php中提交两次表单
- 通过ajax POST提交两次表单
- Ajax表单在包含jcarousel脚本时提交两次
- 表单提交两次,加载两次