【发布时间】:2026-01-10 21:50:01
【问题描述】:
由于某种原因,当我单击一个按钮时,我的控制器和生成的 jquery 函数被调用了两次。由于被调用的js函数是toggle,这是一个问题,因为它会导致代码跳入和跳出视图。
这是表格:
Unseen Notifications: <%= current_user.notification_unseen %> </div>
<%= button_to "show", {:action => "seen", :controller=>"notifications"}, :remote => true %>
这里是控制器:
def seen
respond_to do |format|
format.js
end
end
这里是jquery:
$("div#notifications").toggle();
$("div#count").html("<%= escape_javascript( render :partial => 'notifications/count')%>");
我不知道为什么会发生这种情况。我一直非常小心不要双击,也不知道如何防止它。任何建议将不胜感激。
【问题讨论】:
标签: javascript jquery ruby-on-rails ruby ajax