Topic: Updating a table with link_to_remote

Hi all,

I've spent the past few hours hunting down a bug in my site on IE and Konqueror, which seems to be caused by me attempting to update a <table> tag, rather than a <div>.

This works just fine on all browsers I've tested (IE, Mozilla / Firefox, Konqueror, Opera):

<%= link_to_remote('Update',
    :url=>{
        :controller => "test",
        :action => "update"},
    :update => "testid")
%>
<div id="testid"/>

...

class TestController < ApplicationController
  def update 
    render_text "<table><tr><td>Hello world!</td></tr></table>" 
  end 
end


However, if I attempt to update a <table>, it only works on Mozilla / Firefox:
<%= link_to_remote('Update',
    :url=>{
        :controller => "test",
        :action => "update"},
    :update => "testid")
%>
<table id="testid"/>

...

class TestController < ApplicationController
  def update 
    render_text "<tr><td>Hello world!</td></tr>" 
  end 
end


Have I got the wrong end of the stick here?  Should I even be trying to update something other than a <div> with link_to_remote?

Re: Updating a table with link_to_remote

are you trying to do something to a prticular row or just update the whole table?

If its the whole table, here is what i do for something like that:


view:

<%= link_to_remote('Update', :url=>{:controller => "test", :action => "update"})
%>
<div id="the_table"/>
  <%= render :partial => "the_table" %>
</div>

_the_table.rhtml:
<table>
  <tr id="item_<%= item.id %>">
   <td>Data</td>
  </tr>
</table>

controller:
class TestController < ApplicationController
  def update
    #processing post, etc 
    render :update do |page|
      page.replace_html "the_table", :partial => "the_table"
      # ... more effects if necessary
    end
  end 
end

--jake

---------------------------------------------------------------------
Rails Development - Agile rails consulting and development for startups on a budget
Flvorful Blog - Some ramblings
Flvorful's Open Source Projects - Some handy hacks for your rails projects.

Re: Updating a table with link_to_remote

Thanks - that is in fact exactly what I wound up doing - the initial partial contains the table in the default state, & then subsequent link_to_remote calls update the table to a new state.

What puzzles me though is why updating a <table> only works on some browsers but not others.  Is this a DOM problem on IE & Konqueror, or am I asking more of the AJAX helpers than I should be by asking to update elements other than <div>?