Rails 2 to Rails 3 : using link_to instead of link_to_remote (including remote and update)

99封情书 提交于 2019-12-28 06:23:45

问题


A quick and easy answer I'm sure. I'm upgrading a Rails project from version 2 to version 3 and replacing a load of the link_to_remote with link_to's as per the Rails 3 update. Even something as simple as :

<%= link_to "Check Time",
        {:action=>:get_time}, :remote=>true, :update=>'current_time' %>
<div id='current_time'></div>

doesn't seem to work. The request (using get method) is going through ok and the rendered html is :

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

Routes.rb entry :

get "monitoring/get_time"

As I say I'm sure this is a very obvious issue on my part!


回答1:


The :update option isn't supported by the new link_to :remote => true.

You will either have to

  • use the legacy plugin
  • write the JS/AJAX yourself instead of using :remote => true
  • use render :update { |page| p.replace_html ... }



回答2:


The :update parameter is gone. You need to handle the DOM update yourself using Unobtrusive JavaScript. Also, make sure you actually included the csrf_meta_tag helper in your layout.

I wrote an article about using unobtrusive JavaScript in Rails 3.



来源:https://stackoverflow.com/questions/5511787/rails-2-to-rails-3-using-link-to-instead-of-link-to-remote-including-remote-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!