出于某种原因,当我点击一个按钮时,我的控制器和生成的jquery函数被调用两次.由于调用的js函数是切换,这是一个问题,因为它会导致代码跳入和跳出视图.
这是表格:
Unseen Notifications: <%= current_user.notification_unseen %> </div>
<%= button_to "show", {:action => "seen", :controller=>"notifications"}, :remote => true %>
Run Code Online (Sandbox Code Playgroud)
这是控制器:
def seen
respond_to do |format|
format.js
end
end
Run Code Online (Sandbox Code Playgroud)
这是jquery:
$("div#notifications").toggle();
$("div#count").html("<%= escape_javascript( render :partial => 'notifications/count')%>");
Run Code Online (Sandbox Code Playgroud)
我不知道为什么地球上可能会发生这种情况.我一直非常小心,不要双击,不知道如何防止它.任何建议都会有很大的意义.