javascript - ajax closest is not affected in ruby on rails -
hello newbie in ruby on rails.and try ajax in demo website.delete performed have refresh each time.
view/shared/_feed_item.html.haml
%li{id: feed_item.id} = image_tag current_user.image_url(:small_thumb).to_s %span.user %span.destination %b source: = feed_item.source %span.destination %b destination: = feed_item.destination %span.destination %b date: = feed_item.date %span.timestamp %b time: = feed_item.time %span.content %b comment: = feed_item.content %span.timestamp - if current_user == feed_item.user = link_to "delete", feed_item ,method: :delete, data: { confirm: "you sure?" }, title: "delete", remote: true, class: "delete_post"
view/requests/delete.js.haml
$(document).ready(function(){ $(function(){ $('.delete_post').bind('ajax:success',function() { $(this).closest('li').fadeout(); }); }); });
controller/requests_controller.rb
def destroy @request.destroy respond_to |format| format.html { redirect_to root_url, notice: "post deleted" } format.js { render nothing: true} end end
raw html link
thanks in advance.
the reason why jquery not working. problem turbolinks. $(document).ready(function()
not working turbolinks. more description
Comments
Post a Comment