# Display table data problem

**URL:** <https://www.ruby-forum.com/t/display-table-data-problem/129899>\
**Category:** Rails\
**Created:** [February 22, 2008, 2:33pm UTC](https://www.ruby-forum.com/t/display-table-data-problem/129899 "2008-02-22T14:33:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![annam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e0b2c6/32.png) [@annam](https://www.ruby-forum.com/u/annam)\
**Post date:** [February 22, 2008, 2:33pm UTC](https://www.ruby-forum.com/t/display-table-data-problem/129899/1 "2008-02-22T14:33:30Z")

</div>

Hello! I’m pulling my hair out trying to get a simple view to display  
correctly.

I need to display the practice info for each of the providers in my  
database. Each provider has multiple practices. I would like the  
second, third, fourth … provider\_id, location and provider\_no to  
line up under the first provider\_id, location, etc.

My problem is that each additional practice is added as a new row,  
aligned with the left margin, instead of under the appropriate header.  
I don’t know if this is an html issue, or a ror issue. Because I’m  
dangerously newbie.

This is what the view looks like:

All Providers:  
Title First Name Last Name License ID Location Provider Number  
Dr Tom Close MD 4 RTH T01  
Dr Evan Spam MD 5 RTH T02  
Dr Ted Blue MD 6 RTH T10  
6 RMC N07  
Dr Jack Horner MD 7 RMC N09  
7 RTH T10  
Dr John Left MD 8 RMC N34  
8 RTH T14

This is the view file [lookup.rhtml]:

# All Providers:
\<% for provider in @providers %\> \<% for practice in provider.practices %\> \<% end %\> \<% end %\>

| Title | First Name | Last Name | License | ID | Location | Provider Number |
| --- | --- | --- | --- | --- | --- | --- |
| \<%= provider.title %\> | \<%= provider.first\_name %\> | \<%= provider.last\_name %\> | \<%= provider.lic\_type %\> | \<%= practice.provider\_id %\> | \<%= practice.location %\> | \<%= practice.provider\_no %\> |

  

Here are the models:

class Provider \< ActiveRecord::Base  
has\_many :identifiers  
has\_many :practices  
end

class Practice \< ActiveRecord::Base  
belongs\_to :provider  
end

Here is the related providers\_controller def:

def lookup  
@providers = Provider.find(:all, :include =\>[:practices])  
end

Any insight anyone could provide would be most welcome. Thank you!

---

<div class="post-metadata">

**Author:** ![annam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e0b2c6/32.png) [@annam](https://www.ruby-forum.com/u/annam)\
**Post date:** [February 22, 2008, 3:29pm UTC](https://www.ruby-forum.com/t/display-table-data-problem/129899/2 "2008-02-22T15:29:26Z")

</div>

i’m not sure if i understand exactly how you want to display this,  
a bit of indentation shows at least one obvious error (i think)

\<% for provider in @providers %\>

 \<%= provider.title %\> \<%= provider.first\_name %\> \<%= provider.last\_name %\> \<%= provider.lic\_type %\> \<% for practice in provider.practices %\> \<%= practice.provider\_id %\> \<%= practice.location %\> \<%= practice.provider\_no %\>

```
</tr> <- should be outside loop

```

\<% end %\>  
\<% end %\>

this would most likely work better:  
\<% for provider in @providers %\>

 \<%= provider.title %\> \<%= provider.first\_name %\> \<%= provider.last\_name %\> \<%= provider.lic\_type %\> \<% for practice in provider.practices %\> \<%= practice.provider\_id %\> \<%= practice.location %\> \<%= practice.provider\_no %\> \<% end %\> \<% end %\>

but it wouldn’t work good, since it would leave the first cells empty

this would work better i think  
\<% @providers.each do |provider| %\>

 \<%= provider.title %\> \<%= provider.first\_name %\> \<%= provider.last\_name %\> \<%= provider.lic\_type %\> \<% provider.practices.each do |practice| %\> $nbsp $nbsp $nbsp $nbsp \<%= practice.provider\_id %\> \<%= practice.location %\> \<%= practice.provider\_no %\> \<% end %\> \<% end %\>

but it would create a new row for every practice  
which you could handle with a flag or something like

\<% @providers.each do |provider| %\>

 \<%= provider.title %\> \<%= provider.first\_name %\> \<%= provider.last\_name %\> \<%= provider.lic\_type %\> \<% provider.practices.each\_with\_index do |practice, index| %\> \<% if index == 0 then %\> \<% else %\> $nbsp $nbsp $nbsp $nbsp \<% end %\> \<%= practice.provider\_id %\> \<%= practice.location %\> \<%= practice.provider\_no %\> \<% end %\> \<% end %\>

something on that line should work  
there are a few nice effects you can get with the colspan html attribute  
in cases like that
