Display table data problem

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!

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