jquery tabs and rails : switching causing events to pile up?
I've got two tabs as follows
<div id="tabs">
<ul>
<li ><%= link_to 'A', a_path %></li>
<li ><%= link_to 'B', b_path %></li>
</ul>
</div>
'A' renders with a link as follows: <%= link_to new_foo_path(:format=>:js),:remote=>true %>
When I click that link, I can see in the server log that it gets called two, sometimes 3 times.
I've got no special click handlers set anywhere. My tabs are initialized as follows:
$(function() {
$( "#tabs" ).tabs();
开发者_JS百科});
Worse yet, if I switch back and forth between tabs, there's an increase in the number of remote calls made each time I click that link.
If I take tabs out of the picture, the link works as expected.
I'm running Rails 3 with jquery-1.4.4.min and jquery-ui-1.8.14.custom.min. I've tried other combinations/versions of jquery with no luck. Any ideas anyone?
thanks!
I found the problem. I had this part:
$(function() {
$( "#tabs" ).tabs();
});
In my main application layout template. This was therefore getting called for the content in each of the tabs, which caused that above function to be called multiple times. Once I moved it to the right place, things worked as expected.
Thanks yuval and agmcleod for your input.
精彩评论