草庐IT

ruby-on-rails - Rails 2 到 Rails 3 : using link_to instead of link_to_remote (including remote and update)

coder 2025-06-08 原文

我确定这是一个快速简单的答案。 我正在将 Rails 项目从版本 2 升级到版本 3,并根据 Rails 3 更新将 link_to_remote 的负载替换为 link_to。甚至像 :

这样简单的事情
<%= link_to "Check Time",
        {:action=>:get_time}, :remote=>true, :update=>'current_time' %>
<div id='current_time'></div>

好像不行。请求(使用 get 方法)正常进行,呈现的 html 是:

<a href="/monitoring/get_time" data-remote="true" update="current_time">Check Time</a> 

Routes.rb 条目:

get "monitoring/get_time"

正如我所说,我确信这对我来说是一个非常明显的问题!

最佳答案

新的 link_to :remote => true 不支持 :update 选项。

你要么必须

  • 使用legacy plugin
  • 自己编写 JS/AJAX 而不是使用 :remote => true
  • 使用 render :update { |page| p.replace_html ...

关于ruby-on-rails - Rails 2 到 Rails 3 : using link_to instead of link_to_remote (including remote and update),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5511787/

有关ruby-on-rails - Rails 2 到 Rails 3 : using link_to instead of link_to_remote (including remote and update)的更多相关文章

随机推荐