# Dynamic Table Row

**URL:** <https://www.ruby-forum.com/t/dynamic-table-row/173641>\
**Category:** Rails\
**Created:** [August 12, 2009, 3:24pm UTC](https://www.ruby-forum.com/t/dynamic-table-row/173641 "2009-08-12T15:24:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [August 12, 2009, 3:24pm UTC](https://www.ruby-forum.com/t/dynamic-table-row/173641/1 "2009-08-12T15:24:18Z")

</div>

I’m playing with rails and RJS,

What I want I think sounds simple - but I can’t seem to figure it out.

So basically I have a Countries Model, which joins on Cities Model.

I want to display a list of countries in a select, when you select a  
country it shows all the cities in that country.

That works just fine - the issue I have is to add the data in tables.

I have right now a index page

# Listing countries

| Please select country | \<%= select\_tag(:id , options\_from\_collection\_for\_select(@countries, :id, :country)) %\> |
|
| |

\<%= observe\_field :id, :frequency =\> 0.25, :url =\> {:controller =\> "countries", :action =\> 'show'}, :with =\> 'id' %\>

So when the user chooses a country it gets all the cities of that  
country, now all I want to do is add a new row to the existing table,  
with a new select containing the cities. My show.rjs does

page.replace\_html :show\_cities, :partial =\> ‘show’, :object =\> @country

And then the partial is

Please select city \<%= select\_tag(:id , options\_from\_collection\_for\_select(@country.cities, :id, :title)) %\>

And it displays the data, but not in the exiting table…I know this  
probably isn’t strictly rails as its javascript/html but maybe someone  
can help… All I want is to be able to add new rows when the data is  
available?

---

<div class="post-metadata">

**Author:** ![pmckinstry](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f6c823/32.png) [@pmckinstry](https://www.ruby-forum.com/u/pmckinstry)\
**Post date:** [August 12, 2009, 3:57pm UTC](https://www.ruby-forum.com/t/dynamic-table-row/173641/2 "2009-08-12T15:57:45Z")

</div>

On Aug 12, 2:24 pm, Pete M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> <div id="show_cities"></div>
> 
> ```

Browsers are often a bit finnicky about inserting stuff into tables.  
Strictly speaking you shouldn’t have a div there - a tr should contain  
td tags and things like that. In the past I’ve also found that  
inserting a tbody with some rows to work better than just inserting  
rows.

Fred
