rails 3中的link_to_remote属性/参数

时间:2023-01-17 20:40:04

I'm trying to upgade from rails 2.3 to 3.0 and I've found that link_to_remote in rails 2 should be changed to link_to in rails 3 with :remote => true attribute.

我正试图从rails 2.3升级到3.0,我发现rails 2中的link_to_remote应该更改为rails 3中的link_to:remote => true属性。

And unobtrusive javascript(UJS) for :before, :loading, :failure, :update

并且不引人注目的javascript(UJS)用于:before,:loading,:failure,:update

But I also have attributes like :url, :href, :title how am I supposed to change that ?

但我也有如下属性:url,:href,:title我该怎么改变它?

Here is the rails 2.3 code I'm trying to upgrade

这是我试图升级的rails 2.3代码

 <%= link_to_remote column.label,
  { :url => sort_params,
    :before => "addActiveScaffoldPageToHistory('#{href}', '#{controller_id}')",
    :loading => "Element.addClassName('#{column_header_id}','loading');",
    :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')",
    :update => active_scaffold_content_id,
    :method => :get },
  { :href => href ,
   :title => column.header_info}%>

I've analysed lot of websites and Rails documentation but nothing has specified about these attributes for link_to

我已经分析了很多网站和Rails文档,但没有为link_to指定这些属性

1 个解决方案

#1


0  

You can bind callbacks to remote links in Rails 3, the rest of the attributes can be assigned as options.

您可以将回调绑定到Rails 3中的远程链接,其余属性可以指定为选项。

link_to column.label,
  sort_params,
  remote: true,
  title: column_header.info,
  id: 'my_remote_link',
  data: {
    href: href,
    controller_id: controller_id,
    column_header_id: column_header_id,
    active_scaffold_id: active_scaffold_id
  }

We'll use the data-attributes for the callbacks.

我们将使用数据属性进行回调。

$('#my_remote_link').bind('ajax:beforeSend, function() {
  addActiveScaffoldPageToHistory($('#my_remote_link').data('href'), $('#my_remote_link').data('controller_id'));
});

See http://docs.jquery.com/Ajax_Events for a description of the different ajaxEvents.

有关不同ajaxEvents的说明,请参见http://docs.jquery.com/Ajax_Events。

#1


0  

You can bind callbacks to remote links in Rails 3, the rest of the attributes can be assigned as options.

您可以将回调绑定到Rails 3中的远程链接,其余属性可以指定为选项。

link_to column.label,
  sort_params,
  remote: true,
  title: column_header.info,
  id: 'my_remote_link',
  data: {
    href: href,
    controller_id: controller_id,
    column_header_id: column_header_id,
    active_scaffold_id: active_scaffold_id
  }

We'll use the data-attributes for the callbacks.

我们将使用数据属性进行回调。

$('#my_remote_link').bind('ajax:beforeSend, function() {
  addActiveScaffoldPageToHistory($('#my_remote_link').data('href'), $('#my_remote_link').data('controller_id'));
});

See http://docs.jquery.com/Ajax_Events for a description of the different ajaxEvents.

有关不同ajaxEvents的说明,请参见http://docs.jquery.com/Ajax_Events。