Rails 4 jquery link with bind firing on reload -
hi have strange behaviour in rails 4. have partial next code:
#add_tabs = link_to "add tab", "#", id:"test" #data_retrieved :javascript $("#test").bind("click",function(){ alert("i'm working"); });
and everythime reload page alert fired. i'm lost.
thanks in advance.
update:
thanks pavan realised happened. rails 4.1.8 uses turbolinks manages links on site in order preloaded. therefore everytime site reloads links fired. prevent behaviour must (as pointed pavan) set links remote: true in order let them managed ajax/javascript event. this:
link_to "add tab", "#", id:"test", remote: true
also, , more important, must use
gem 'jquery-turbolinks'
and sure application.js looks this:
/= require jquery //= require jquery.turbolinks //= require jquery_ujs // // ... other scripts here ... // //= require turbolinks
last not least, sure binding callbacks set way:
$("#test").bind("click",function(){get_products()})
because if set way:
$("#test").bind("click",get_products())
strange thing happen ;)
Comments
Post a Comment