导轨的link_to:远程 [英] rails link_to :remote

查看:111
本文介绍了导轨的link_to:远程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下几点:

<%= link_to my_path, method: :delete, confirm: 'Delete?', class: 'link-delete', 'data-message' => 'Are you sure?', 'data-severity' => 'danger', :remote => true do %>
  <i class="icon-trash"></i>
<% end %>

这带来了一个引导程序模态进行确认,我想钩住AJAX调用,这样我可以显示一个微调或某些类型的文本。

which brings up a Bootstrap Modal for confirmation, and I wanted to hook onto the ajax call that so that I can display a spinner or some kind of text.

我知道,我可以用不显眼的JavaScript来听,像这样的单击事件,如果我不使用':远程=>真正的'在我的link_to

I know that I can use unobtrusive javascript to listen to the click event like so, if I DON'T use ':remote => true' in my link_to

jQuery ->
  $('.link-delete').live 'click', (event) ->
    $('.link-delete').html("Loading...")  #THE MSG OR ANIMATION I WANT TO DISPLAY
    $.get(this.href, null, null, 'script')
   false

但不知道如何将两者结合起来使用时:远程=>真正的

but not sure how to combine the two when using ':remote => true'

有什么建议?

感谢您的帮助

推荐答案

您可以绑定到这样的AJAX调用:

You can bind to ajax calls like this:

<%= link_to my_path, method: :delete, confirm: 'Delete?', class: 'link-delete', 'data-message' => 'Are you sure?', 'data-severity' => 'danger', :remote => true do %>
  <i class="icon-trash"></i>
<% end %>

$('.link-delete').bind('ajax:beforeSend', function() {
  $('#mySpinner').show();
});

$('.link-delete').bind('ajax:complete', function() {
  $('#mySpinner').hide();
});

这篇关于导轨的link_to:远程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆