【问题标题】:Post ajax request with link_to doesn't work使用 link_to 发布 ajax 请求不起作用
【发布时间】:2013-10-14 00:52:47
【问题描述】:

我对 link_to 方法有这样的看法:

= link_to "Add Friend", friendships_path(:id => @user), :method => :post, :remote => true

如您所见,我想使用 ajax(远程:true)发送带有 link_to 的发布请求。

此请求转到友谊控制器中的创建方法,它工作正常(它创建关系)但它呈现任何东西(萤火虫告诉我:500 内部服务器错误)。

views/friendships/create.js.erb

$("#my_selector").html("<%= escape_javascript(render('users/cancel_invitation')) %>")

视图/用户/cancel_invitation

= link_to "Cancel request", { :controller => "friendships", :action => "cancel", :id => @user }, data: { confirm: "Cancel friendship request?" }

我找不到错误。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4


    【解决方案1】:

    = link_to "Cancel request", { :controller =&gt; "friendships", :action =&gt; "cancel", :id =&gt; @user }, data: { confirm: "Cancel friendship request?" }, :remote =&gt; true

    :remote =&gt; true 位对于 ajaxy 的东西很重要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-04
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 2013-12-01
      • 2017-05-25
      • 1970-01-01
      相关资源
      最近更新 更多