Collect with habtm

So, I need Rails to display the values of a query string value (a last
initial). The current controller looks like this:

def index
@letters = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”.split("")
if params[:id]
@initial = params[:id]
@pages, providers = paginate(:providers,
:conditions => [“last_name LIKE ?”,
@initial+’%’],
:order => “last_name, first_name”)
@providers = providers.collect { |provider| provider }
@levels = Level.find(:all)
end
end

The view looks like this:

<% if @pages %>

Found <%= pluralize(@pages.item_count, "match") %>.

<% end %>

<% for level in @levels %>
<% for provider in level.providers %>
<% for provider in @providers %>

display various provider attributes

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

<% end

The results of this view does correctly display the number of results
for the query, but it displays all the values for the providers,
regardless of how many match the given query.

Obviously, in the providers model, there is a has_and_belongs_to_many
:levels

Thanks for any help on this.