Hello. In my app jquery script runs strange and wrong. So I have usuall .js.erb template, which is called from controller by format.js This template is just for testing now, so it only calls alert message, if some links are clicked. I didn''t modify default layout document. The problem is that on first click nothing happens, than it alerts as many times, as all links was clicked until this moment. So 1st time click - zero alerts, 2 time click - 1 alert, 3 time click - 2 alerts and so on. The code of Jquery file is so simple, that definetely not the source of problem. May be some ideas? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/xhLJSqVkFv8J. For more options, visit https://groups.google.com/groups/opt_out.
But for the sake of stupid errors in simple things I''ll post jquery code: $(''.keyword_links'').ready(function(){ var keywords = $(''.keyword_links''); function addField(){ alert(''True''); } keywords.bind("click", addField); }); -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/7X60FPjHzm8J. For more options, visit https://groups.google.com/groups/opt_out.
Barry wrote in post #1101300:> But for the sake of stupid errors in simple things I''ll post jquery > code: > > $(''.keyword_links'').ready(function(){ > var keywords = $(''.keyword_links''); > function addField(){ > alert(''True''); > } > keywords.bind("click", addField); > });What you show here is not the proper way to use the ready AFAIK. Try this instead: $(document).ready(function() { $(''.keyword_links'').bind(''click'', addField); }); function addField() { alert(''True''); } // Or the shorthand version $(function() { $(''.keyword_links'').click(function() { alert(''True'') }); }); // Even more awesome use CoffeeScript $ -> $(''.keyword_links'').click -> alert(''True'') -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Robert Walker wrote in post #1101305:> Barry wrote in post #1101300: >> But for the sake of stupid errors in simple things I''ll post jquery >> code: >> >> $(''.keyword_links'').ready(function(){ >> var keywords = $(''.keyword_links''); >> function addField(){ >> alert(''True''); >> } >> keywords.bind("click", addField); >> }); > > What you show here is not the proper way to use the ready AFAIK.Forgot to include the documentation reference: http://api.jquery.com/ready/ -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
no, this didn''t solve this (( -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/LbhHK4LCNOMJ. For more options, visit https://groups.google.com/groups/opt_out.
no, this didn''t solve problem среда, 13 марта 2013 г., 2:56:58 UTC+4 пользователь Barry написал:> > Hello. > In my app jquery script runs strange and wrong. So I have usuall .js.erb > template, which is called from controller by format.js > This template is just for testing now, so it only calls alert message, if > some links are clicked. I didn''t modify default layout document. > The problem is that on first click nothing happens, than it alerts as many > times, as all links was clicked until this moment. > So 1st time click - zero alerts, 2 time click - 1 alert, 3 time click - 2 > alerts and so on. > The code of Jquery file is so simple, that definetely not the source of > problem. > May be some ideas? >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/yzxsxdzyY44J. For more options, visit https://groups.google.com/groups/opt_out.
Barry wrote in post #1101311:> no, this didn''t solve this ((It worked as expected in my quick test. You haven''t provided enough information for me to help further. For instance I don''t know what your HTML looks like. How many elements are matched by the jQuery selector, etc. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
ok... more code. in tests_controller method which calls js file: def add_key @test=Test.find(params[:id]) @key=@test.keys.build @key.keyword = params[:keyword] @key.position = params[:position] @answer = generate_answer_field(@key.position) respond_to do |format| if @key.save then format.js end end end it calls add_key.js.erb with code from first post in show view link on which jquery called: <%= link_to(result_array[k], {:controller =>''tests'', :action => ''add_key'', :keyword => result_array[k], :position=>k}, :class=>''keyword_links'', :method => :post, :remote => true) + str %> <a href="/tests/143/add_key?keyword=Forever&position=18" class="keyword_links" data-method="post" data-remote="true" rel="nofollow">Forever</a> And finally to mention, that actually I don''t have real route for this link coz all it need to render some form and save smth to database. Link works - saves that info to database. Problem goes with Jquery. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/JcXyJS4DOL0J. For more options, visit https://groups.google.com/groups/opt_out.
A lot of such links from array output. But problem is maintaining with one link etc. среда, 13 марта 2013 г., 5:19:34 UTC+4 пользователь Ruby-Forum.com User написал:> > Barry wrote in post #1101311: > > no, this didn''t solve this (( > > It worked as expected in my quick test. You haven''t provided enough > information for me to help further. For instance I don''t know what your > HTML looks like. How many elements are matched by the jQuery selector, > etc. > > -- > Posted via http://www.ruby-forum.com/. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/adK7llFRSWYJ. For more options, visit https://groups.google.com/groups/opt_out.
guys, I found out everything. As always, I''m stupid. Hope, this topic will help someone to avoid this type of mistake. So, I got controller, which respond to js.ERB file. This js.erb file is called when controller method called, that means it doesn''t suit to handle some events inside of it. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/eJU8mydl460J. For more options, visit https://groups.google.com/groups/opt_out.
$(''#<%=j @key.position.to_s %>'').hide().after(''<%= j render(''generate_answer_field'') %>''); works perfectly) i''m dumb) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Qy1rGUNm-vwJ. For more options, visit https://groups.google.com/groups/opt_out.