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 %> <tr> <td><%= bes.bes_displayname %></td> <td><%= bes.bes_phonenumber %></td> <td><%= import.prov_service_number %></td> </tr> <% 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
thatcher.craig-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-29 02:38 UTC
Re: Quick Compare Question...
"@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 Miller <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 %> > <tr> > <td><%= bes.bes_displayname %></td> > <td><%= bes.bes_phonenumber %></td> > <td><%= import.prov_service_number %></td> > </tr> > <% 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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 28, 2008, at 6:25 PM, Jeff Miller wrote:> > 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 %> > <tr> > <td><%= bes.bes_displayname %></td> > <td><%= bes.bes_phonenumber %></td> > <td><%= import.prov_service_number %></td> > </tr> > <% 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 MillerI 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 -%> <tr> <td><%= match.name %></td> <td><%= match.number %></td> <td><%= match.prov_number %></td> </tr> <% end %> Does something like this seem sensible? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---