Hello,
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 }
end
end
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 %>
<%= bes.bes_displayname %> |
<%= bes.bes_phonenumber %> |
<%= import.prov_service_number %> |
<% 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!
“@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…
On Jan 28, 9:25 pm, Jeff M. [email protected]
On Jan 28, 2008, at 6:25 PM, Jeff M. wrote:
@bes = Bes.find(:all)
looks like this:
types
of variables and RoR in general.
Thank you very much!
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 -%>
<%= match.name %> |
<%= match.number %> |
<%= match.prov_number %> |
<% end %>
Does something like this seem sensible?