1

我是 Ruby on Rails 的初学者。在 ROR 的帮助下,我已经能够构建一个小型应用程序。

我想在不加载整个页面的情况下获取并加载我的一些数据。在点击不同的链接时,数据应上传到相应的 div 中。我正在尝试在链接上提供 :remote=>true 属性。但是此属性未正确呈现属性。

在使用 Ajax 跟踪 Rails 上的多个链接后,我发现视图中的链接应为:

<%= link_to cateogary.cateogary_name, :controller => "cateogaries", :action => "show_async", :id => cateogary_id, :remote => true %>

这应该转换为:

<a href="/cateogaries/12/show_async data-remote=true">

虽然,这被转换为:

<a href="/cateogaries/12/show_async?remote=true">

可能的原因是什么?请转发一些在 ROR 中提供完整 Ajax 实现的好链接。

4

1 回答 1

1

Rails 将其识别:remote => true为 URL 的参数。试试这个:

<%= link_to cateogary.cateogary_name, { :controller => "cateogaries", :action => "show_async", :id => cateogary_id }, :remote => true %>

或者也许是这样:

<%= link_to cateogary.cateogary_name, "/cateogaries/#{cateogary_id}/show_async", :remote => true %>

此外,我建议您阅读内容(并检查链接)。

于 2012-07-02T17:18:35.310 回答