【问题标题】:Rails 3.2 with Ajax implementation带有 Ajax 实现的 Rails 3.2
【发布时间】:2012-07-02 17:13:15
【问题描述】:

我是 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 实现的好链接。

【问题讨论】:

    标签: ruby-on-rails ajax ruby-on-rails-3.2


    【解决方案1】:

    Rails 将 :remote =&gt; 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 %>
    

    此外,我建议您阅读this(并查看链接)。

    【讨论】:

      猜你喜欢
      • 2013-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-24
      • 2012-11-01
      • 1970-01-01
      相关资源
      最近更新 更多