How to handle JavaScript events (e.g. 'link_to :remote') the Rails Way? -


i using ruby on rails 4 , handle javascript events rails way. is, example, given have following

link_to('destroy', article_path(@article), :method => :delete, :remote => true) 

when click on above generated link success js event update page content removing deleted article dom element. ajax response, whatever is, should ignored.

i aware of existence of rails.js file don't how use in order accomplish looking for.

there wiki page https://github.com/rails/jquery-ujs/wiki/ajax explanation of ujs custom events. here little example in case:

$('a').on 'ajax:success', -> alert 1 

upd if want prevent xhr response being evaluated, add data-type=text attribute remote link:

link_to('destroy', article_path(@article), :method => :delete, :remote => true, 'data-type' => 'text') 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -