Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 链接是否有:之前和/或:之后,如链接到远程_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 链接是否有:之前和/或:之后,如链接到远程

Ruby on rails 链接是否有:之前和/或:之后,如链接到远程,ruby-on-rails,ruby,Ruby On Rails,Ruby,我正在使用link\u to将我的一些link\u转换为\u remote生成器,因为AJAX调用在我的浏览器后退按钮上产生了问题。(愚蠢的错误!) 我的应用程序有很多页面,它们的等待周期很长(由于各种原因我无法控制)。我一直依赖于link-to-u-remote的功能,在用户等待时使用:before和:after调用来显示微调器。链接到的是否有类似的内容?我假设只是把电话扔进去,就像我用link\u to\u remote。。。但这只适用于:before调用(而且它似乎不起作用)。目前我的其他

我正在使用
link\u to
将我的一些
link\u转换为\u remote
生成器,因为AJAX调用在我的浏览器后退按钮上产生了问题。(愚蠢的错误!)


我的应用程序有很多页面,它们的等待周期很长(由于各种原因我无法控制)。我一直依赖于link-to-u-remote的功能,在用户等待时使用
:before
:after
调用来显示微调器。链接到的
是否有类似的内容?我假设只是把电话扔进去,就像我用
link\u to\u remote
。。。但这只适用于
:before
调用(而且它似乎不起作用)。目前我的其他选择是什么?

由于link_to生成了一个简单的锚供用户点击,所以最好的选择可能是为document.onunload添加javascript处理程序以替换:before处理程序。您是:after handlers;-)的SOL请查看Prototype的Event.observe(),或者使用RJS实现更好的Rails集成。

由于link\u可以生成一个简单的锚供用户点击,因此最好的选择可能是为document.onLoad添加javascript处理程序,以替换:before处理程序。您是:after handlers;-)的SOL查看Prototype的Event.observe(),或者使用RJS实现更好的Rails集成。

链接到“单击我”,你的url:onclick=>“javascript”

链接到“单击我”,你的url:onclick=>“javascript”

如果你愿意学习一点javascript,我发现在jQuery中做同样的事情既快又容易。听起来您仍然在进行AJAX调用,只是
链接到远程
行为产生了不幸的副作用

如果Rails视图代码如下所示:

<%= link_to "Show me", slow_page_url, :class => 'remote', :'data-update' => 'display' %>
'remote',:'data-update'=>'显示'%>
我想添加一个jQuery块,如下所示:

<% content_for :dom_ready do %>
  // register a callback for the click event on links with class 'remote'

  $('a.remote').click( function() {

    // this is the clicked_link, which you may want to 
    // persist thru several levels of callbacks
    // so assign it to a local variable

    var clicked_link = this;

    // assuming you already have a start_spinner function, 
    // and you might pass it the object where the click occured

    start_spinner(clicked_link);

    // here's the ajax call, which will automatically update 
    // the div you identified using the data-update attribute 
    // with the returned html

    $('#'+$(this).attr('data-update')).load( $(this).attr('href'), {}, function() {

       //this callback only runs when the AJAX request has completed

      stop_spinner( clicked_link );

    } );

    // prevents the click event from propagating to the window object 
    //and moving the user away from the current page

    return false;
  } );
<% end %>

//在类为“remote”的链接上注册click事件的回调
$('a.remote')。单击(函数(){
//这是单击的链接,您可能希望
//通过几个级别的回调保持
//所以把它赋给一个局部变量
var\u link=this;
//假设您已经有了一个start\u微调器函数,
//您可以将发生单击的对象传递给它
启动微调器(单击链接);
//这里是ajax调用,它将自动更新
//使用数据更新属性标识的div
//使用返回的html
$('#'+$(this.attr('data-update')).load($(this.attr('href'),{},function(){
//此回调仅在AJAX请求完成时运行
停止旋转器(单击链接);
} );
//防止单击事件传播到窗口对象
//以及将用户从当前页面移开
返回false;
} );
然后我将所有javascript加载到布局的底部,如下所示

<%= javascript_include_tag 'jquery-1.3.2.js' %>
<script type="text/javascript">
$( function() {
  <%= yield :dom_ready %>
);
</script>

$(函数(){
);

如果您愿意学习一点Javascript,我发现在jQuery中做同样的事情既快又简单。听起来您仍然在做AJAX调用,只是
链接到远程
的行为产生了不幸的副作用

如果Rails视图代码如下所示:

<%= link_to "Show me", slow_page_url, :class => 'remote', :'data-update' => 'display' %>
'remote',:'data-update'=>'显示'%>
我想添加一个jQuery块,如下所示:

<% content_for :dom_ready do %>
  // register a callback for the click event on links with class 'remote'

  $('a.remote').click( function() {

    // this is the clicked_link, which you may want to 
    // persist thru several levels of callbacks
    // so assign it to a local variable

    var clicked_link = this;

    // assuming you already have a start_spinner function, 
    // and you might pass it the object where the click occured

    start_spinner(clicked_link);

    // here's the ajax call, which will automatically update 
    // the div you identified using the data-update attribute 
    // with the returned html

    $('#'+$(this).attr('data-update')).load( $(this).attr('href'), {}, function() {

       //this callback only runs when the AJAX request has completed

      stop_spinner( clicked_link );

    } );

    // prevents the click event from propagating to the window object 
    //and moving the user away from the current page

    return false;
  } );
<% end %>

//在类为“remote”的链接上注册click事件的回调
$('a.remote')。单击(函数(){
//这是单击的链接,您可能希望
//通过几个级别的回调保持
//所以把它赋给一个局部变量
var\u link=this;
//假设您已经有了一个start\u微调器函数,
//您可以将发生单击的对象传递给它
启动微调器(单击链接);
//这里是ajax调用,它将自动更新
//使用数据更新属性标识的div
//使用返回的html
$('#'+$(this.attr('data-update')).load($(this.attr('href'),{},function(){
//此回调仅在AJAX请求完成时运行
停止旋转器(单击链接);
} );
//防止单击事件传播到窗口对象
//以及将用户从当前页面移开
返回false;
} );
然后我将所有javascript加载到布局的底部,如下所示

<%= javascript_include_tag 'jquery-1.3.2.js' %>
<script type="text/javascript">
$( function() {
  <%= yield :dom_ready %>
);
</script>

$(函数(){
);
另请参见:另请参见: