8

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!

detheridge02
  • 640
  • 1
  • 6
  • 18

2 Answers2

17

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 ... }
Marcel Jackwerth
  • 53,948
  • 9
  • 74
  • 88
  • 6
    You don't need to completely replace :remote => true. Use it, and bind the built in callback events from rails.js: 'ajax:before', 'ajax:complete', 'ajax:success', 'ajax:failure'. – Martin Svalin Jun 26 '12 at 13:55
  • The article ["Unobtrusive JavaScript in Rails 3"](http://bit.ly/aCdHWY) is a bit dated (June 8th, 2010) but has some examples of binding on these events. – Jared Beck Feb 08 '13 at 22:58
7

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.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
  • 1
    csrf_meta_tag included in main layout. Seems to be the one problem with Ruby, functionality appearing and disappearing almost overnight. I can understand the reason to remove :update but it was a very useful bit of code! Thanks for your help. – detheridge02 Apr 01 '11 at 10:08
  • Yep I meant Rails :-) Can't you tell I'm a PHP coder having to get to grips with Ruby :-) Great article by the way! – detheridge02 Apr 01 '11 at 10:15