Ajax table does not update

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:


<%= link_to 'Days', :action => 'show_days', :id => child %>

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 -%>

<%=h day.startdate %> <%=h day.enddate %> <% end -%>

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

try {
Element.update(“show_days”, "

2005-09-01\n 2006-07-01\n"); Effect.toggle("show_days",'appear',{duration:0.5}); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('Element.update(\"show_days\", \" 2005-09-01\n 2006-07-01\n\");\nEffect.toggle(\"show_days\",\'appear\',{duration:0.5});'); throw e }

What am I doing wrong?

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} %>

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???


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

<% for child in @children %>

<% end %>

The “colspan=9” did the trick.

Hope I can save somebody else some time with this post!