Quick Compare Question...

My controller is supposed to compare values from a particular column in
two different DB tables to find matches and non-matches. I keep on
getting an "undefined local variable or method 'bes'" error. My
controller looks like this:

class CompareController < ApplicationController
  def index
    @bes = Bes.find(:all)
    @prov = Import.find(:all)

    @matches = @prov.select { |prov| prov.prov_service_number ==
bes.bes_phonenumber }

Above, BES is a table housing my company's BlackBerry mobile phone
information, and PROV is a table housing our provider's records. My view
looks like this:

<% for import in @matches %>
    <td><%= bes.bes_displayname %></td>
    <td><%= bes.bes_phonenumber %></td>
    <td><%= import.prov_service_number %></td>
<% end %>

Can anybody help me with this? I'm still a newbie on the different types
of variables and RoR in general.

Thank you very much!
- Jeff Miller

"@matches = @prov.select { |prov| prov.prov_service_number ==
bes.bes_phonenumber }"
should by @matches = @prov.select { |prov| prov.prov_service_number ==
@bes.bes_phonenumber }

you are declaring a variable but not using it. I dont' think the view
will work as is.....

I think you'll save yourself some time by doing a find_by_sql here:

@matches = Bes.find_by_sql(
   "SELECT BES.bes_phonenumber number, BES.bes_displayname name, PROV.prov_service_number prov_number
   FROM PROV, BES WHERE PROV.provider_service_number = BES.bes_phonenumber")

That way your database can do the heavy lifting, matching up all the records. Then in your view:

<% for match in @matches -%>
     <td><%= match.name %></td>
     <td><%= match.number %></td>
     <td><%= match.prov_number %></td>
<% end %>

Does something like this seem sensible?