Forum: Ruby on Rails Ajax table does not update

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
oom tuinstoel (Guest)
on 2006-06-04 15:24
I have two models: Child and Day. A Child has many days, and a day
belongs to a child.

I want to create ana ajax table listing the children and, after pressing
a button, I want to show the days that belong to that child.

Here is my code:

    <td><%= link_to 'Days', :action => 'show_days', :id => child %></td>
    <div id="show_days" style="display: none"></div>

  def show_days
    @child = Child.find(params[:id])
    @days = @child.days

page.replace_html 'show_days', :partial => 'days', :collection => @days
page.visual_effect :toggle_appear, 'show_days', 'duration' => 0.5

<% for day in @days -%>
  <td><%=h day.startdate %></td>
  <td><%=h day.enddate %></td>
<% end -%>

The problem is, in Firefox I get a new page with the following text:

try {
Element.update("show_days", "  <td>2005-09-01</td>\n
} catch (e) { alert('RJS error:\n\n' + e.toString());
alert('Element.update(\"show_days\", \"  <td>2005-09-01</td>\n
throw e }

What am I doing wrong?
Alex W. (Guest)
on 2006-06-04 22:25
oom tuinstoel wrote:
>     <td><%= link_to 'Days', :action => 'show_days', :id => child %></td>

You're not using ajax, just a standard link_to.  So rails renders the
javascript and sends it with text/html headers and is displayed as text
by the browser on a new page.

You must start the ajax request by using link_to_remote:

  <%= link_to_remote 'Days', :url => {:action => 'show_days', :id =>
child} %>
oom tuinstoel (Guest)
on 2006-06-05 15:03
>Alex W. wrote:
>   <%= link_to_remote 'Days', :url => {:action => 'show_days', :id =>
> child} %>

Yes Ales, you are absolutely right. But... it is still not working! Is
there something else I am overlooking????
oom tuinstoel (Guest)
on 2006-06-05 21:35

Yes, I found it myself! Here's how I did it:


 <% for child in @children %>
        <td colspan="9"><div id='days' style="display: none"></td>
  <% end %>

The "colspan=9" did the trick.

Hope I can save somebody else some time with this post!
This topic is locked and can not be replied to.