【问题标题】:Rails 3 :remote => true does not trigger AJAX requestsRails 3 :remote => true 不会触发 AJAX 请求
【发布时间】:2011-04-24 22:05:19
【问题描述】:

我有以下:

<%= link_to "Exhibitions", :action => 'tabExhibitions', :id => @app.id, :remote => true %>

它生成:

<div class="tabbarButton" id="tabbarExhibitions">
    <a href="/apps/3/tabExhibitions?remote=true">Exhibitions</a>
</div>

点击时会产生一个常见的 GET 请求。

我是 Rails 新手,但我的理解是设置 :remote =&gt; true 应该创建一个 &lt;a href="..." data-remote=true&gt; 而不是普通链接。

我正在使用 jQuery,必要的标题和元标记都已到位。我应该提到这个项目是从 Rails 2.3.8 升级的

感谢大家的帮助。

【问题讨论】:

    标签: ajax ruby-on-rails-3


    【解决方案1】:

    link_to:remote =&gt; true 放入参数列表的url 部分,并为其创建一个查询字符串参数(参见参数in the documentation)。基本上,你写的是:

    <%= link_to "Exhibitions", { :action => 'tabExhibitions', :id => @app.id, :remote => true } %>
    

    您需要为html_options 设置一个单独的哈希:

    <%= link_to "Exhibitions", { :action => 'tabExhibitions', :id => @app.id }, :remote => true %>
    

    【讨论】:

    • 谢谢,同样的事情也发生在我身上
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-28
    相关资源
    最近更新 更多