# Ajax table does not update

**URL:** <https://www.ruby-forum.com/t/ajax-table-does-not-update/62415>\
**Category:** Rails\
**Created:** [June 4, 2006, 1:24pm UTC](https://www.ruby-forum.com/t/ajax-table-does-not-update/62415 "2006-06-04T13:24:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 4, 2006, 1:24pm UTC](https://www.ruby-forum.com/t/ajax-table-does-not-update/62415/1 "2006-06-04T13:24:46Z")

</div>

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:

(list.rhtml)

 ... 

| \<%= link\_to 'Days', :action =\> 'show\_days', :id =\> child %\> |
|
| |

(child\_controller  
def show\_days  
@child = Child.find(params[:id])  
@days = @child.days  
end

(child.chow\_days.rjs)  
page.replace\_html ‘show\_days’, :partial =\> ‘days’, :collection =\> @days  
page.visual\_effect :toggle\_appear, ‘show\_days’, ‘duration’ =\> 0.5

(\_days.rhtml)  
\<% 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?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 4, 2006, 8:25pm UTC](https://www.ruby-forum.com/t/ajax-table-does-not-update/62415/2 "2006-06-04T20:25:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 5, 2006, 1:03pm UTC](https://www.ruby-forum.com/t/ajax-table-does-not-update/62415/3 "2006-06-05T13:03:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 5, 2006, 7:35pm UTC](https://www.ruby-forum.com/t/ajax-table-does-not-update/62415/4 "2006-06-05T19:35:09Z")

</div>

IT WORKS!

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!
