Here''s the code https://gist.github.com/dasibre/6786245 *new.js.erb file has the following js code* $(''a.pinbutton'').on(''click'', function() { $(this).parent().append(''<%= escape_javascript(render("select")) %>'') }); *here''s the player index with the new link* <%= link_to "Pin", {controller: "pinboard_players", action: "new", id: player}, remote: true, class: "pinbutton", id: "#{player.id}" %> *controller new action action:* def new session[:player] = params[:id] @pinboard_player = PinboardPlayer.new(player_id: params[:id]) @current_user_pinboards = get_user_pinboards respond_to do |format| format.html format.js end end When I click on the button, to display the select form, it takes two clicks for the javascript to work. -- 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/msgid/rubyonrails-talk/8faeeb6f-d5c1-4c36-924a-4e59a0397279%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
On 2 October 2013 23:06, dasibre <james.naadjie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Here''s the code > https://gist.github.com/dasibre/6786245 > > new.js.erb file has the following js code > > $(''a.pinbutton'').on(''click'', function() { > $(this).parent().append(''<%= escape_javascript(render("select")) %>'') > }); > > here''s the player index with the new link > <%= link_to "Pin", {controller: "pinboard_players", action: "new", id: > player}, remote: true, class: "pinbutton", id: "#{player.id}" %> > > controller new action action: > def new > session[:player] = params[:id] > @pinboard_player = PinboardPlayer.new(player_id: params[:id]) > @current_user_pinboards = get_user_pinboards > respond_to do |format| > format.html > format.js > end > end > > When I click on the button, to display the select form, it takes two clicks > for the javascript to work.Have a look in development.log to see what is happening when you press it the first time, then the second. Colin -- 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/msgid/rubyonrails-talk/CAL%3D0gLsadi6H-z6iCWg%2B5u2Ncd_jP1XGF%2BYO_%3Dgp4aFwfHbjaA%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Your view that has the link link_to ''Pin'' already binds the event and points to the new action so you won''t need to bind the event again to this link in new.js.erb. Conclusion is your new.js.erb has problems. Replace your new.js.erb code with the following: $(''a.pinbutton'').parent().append(''<%= escape_javascript(render("select")) %>'') regards, Sur crimson9.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/msgid/rubyonrails-talk/193a08cd-21b7-4a15-8c52-f9942bc76130%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.