Hello,
I am getting a very strange error... I am working on a view that
compares a phone number in one model to a phone number in another model
and displays the matches and non-matches. However, when I try to do a
comparison using != it just pumps out hundreds of repeating lines. My
view looks like this:
<table border="0" cellpadding="0"
cellspacing="0" width="100%">
<tr>
<td width="50%" valign="top">
<table border="0" cellpadding="0"
cellspacing="0" width="100%">
<tr><td colspan="2">
<font size="2"
face="verdana"><b>Matches</b></font>
</td></tr>
<% for bes in @bes %>
<% if bes.bes_phonenumber.to_s.size == 11 %>
<% bes.bes_phonenumber = bes.bes_phonenumber.to_s.slice(1..11) %>
<% bes.bes_phonenumber.to_i %>
<% end %>
<% for import in @prov %>
<% if bes.bes_phonenumber == import.prov_service_number %>
<tr>
<td><%= bes.bes_displayname %></td>
<td><%= bes.bes_phonenumber %></td>
</tr>
<% end %>
<% end %>
<% end %>
</table>
</td>
<td width="50%" valign="top">
<table border="0" cellpadding="0"
cellspacing="0" width="100%">
<tr><td colspan="2"><font size="2"
face="verdana"><b>Non-Matches</b></font></td></tr>
<% for bes in @bes %>
<% if bes.bes_phonenumber.to_s.size == 11 %>
<% bes.bes_phonenumber = bes.bes_phonenumber.to_s.slice(1..11) %>
<% bes.bes_phonenumber.to_i %>
<% end %>
<% for import in @prov %>
<% if bes.bes_phonenumber == import.prov_service_number returns false
%>
<tr>
<td><%= bes.bes_displayname %></td>
<td><%= bes.bes_phonenumber %></td>
</tr>
<% end %>
<% end %>
<% end %>
</table>
</td>
</tr>
</table>
The first one works perfectly (I think) but the second just pumps out
about 100 rows of each bes_displayname and bes_phonenumber. Does anybody
know what is causing the error? I tried to find a comparison operator in
Ruby to say "not equals" but came up short... Is != not part of Ruby?
Thanks,
- 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
-~----------~----~----~----~------~----~------~--~---
oops, what I posted was the wrong thing, sorry...
The relevant part of the code is this:
<% for bes in @bes %>
<% if bes.bes_phonenumber.to_s.size == 11 %>
<% bes.bes_phonenumber = bes.bes_phonenumber.to_s.slice(1..11) %>
<% bes.bes_phonenumber.to_i %>
<% end %>
<% for import in @prov %>
<% if bes.bes_phonenumber != import.prov_service_number %>
<tr>
<td><%= bes.bes_displayname %></td>
<td><%= bes.bes_phonenumber %></td>
<td><%= import.prov_service_number %></td>
</tr>
<% end %>
<% end %>
<% end %>
Thanks!
--
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
-~----------~----~----~----~------~----~------~--~---
What is bes and prov? Please don''t shorten the variable names as it
makes it
harder for other programmers to understand what the code is about.
You can do a select method call on the @prov collection and put the
condition in there, without the if.
@prov.select { |prov| prov.number != bes.number }
On Jan 23, 2008 11:27 AM, Jeff Miller
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
>
> oops, what I posted was the wrong thing, sorry...
>
> The relevant part of the code is this:
>
> <% for bes in @bes %>
> <% if bes.bes_phonenumber.to_s.size == 11 %>
> <% bes.bes_phonenumber = bes.bes_phonenumber.to_s.slice(1..11) %>
> <% bes.bes_phonenumber.to_i %>
> <% end %>
>
> <% for import in @prov %>
> <% if bes.bes_phonenumber != import.prov_service_number %>
>
> <tr>
> <td><%= bes.bes_displayname %></td>
> <td><%= bes.bes_phonenumber %></td>
> <td><%= import.prov_service_number %></td>
> </tr>
> <% end %>
>
> <% end %>
> <% end %>
>
> Thanks!
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--
Ryan Bigg
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
On 23 Jan 2008, at 00:18, Jeff Miller wrote:> > <td width="50%" valign="top"> > <table border="0" cellpadding="0" cellspacing="0" width="100%"> > <tr><td colspan="2"><font size="2" > face="verdana"><b>Non-Matches</b></font></td></tr> > <% for bes in @bes %> > <% if bes.bes_phonenumber.to_s.size == 11 %> > <% bes.bes_phonenumber = bes.bes_phonenumber.to_s.slice(1..11) %> > <% bes.bes_phonenumber.to_i %> > <% end %> >Random guess: you think bes.bes_phonenumber.to_i is actually changing bes.bes_phonenumber. It isn''t> <% for import in @prov %> > <% if bes.bes_phonenumber == import.prov_service_number returns false > %> >Not sure what you''re on about here, ''returns'' isn''t a ruby thing, and rather meaningless in the context of a view. All this messing around with slicing strings etc. either belongs in a model (if this is a data normalization thing) or in a helper of some sort, as it makes views confusing and/or messy Fred> <tr> > <td><%= bes.bes_displayname %></td> > <td><%= bes.bes_phonenumber %></td> > </tr> > <% end %> > > <% end %> > <% end %> > </table> > </td> > </tr> > </table> > > The first one works perfectly (I think) but the second just pumps out > about 100 rows of each bes_displayname and bes_phonenumber. Does > anybody > know what is causing the error? I tried to find a comparison > operator in > Ruby to say "not equals" but came up short... Is != not part of Ruby? > > Thanks, > - 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 -~----------~----~----~----~------~----~------~--~---