Comparison not working

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:

<% 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 %>

<% end %>

<% end %>
<% end %>

Matches
<%= bes.bes_displayname %> <%= bes.bes_phonenumber %>
<% 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
%>

<% end %>

<% end %>
<% end %>

Non-Matches
<%= bes.bes_displayname %> <%= bes.bes_phonenumber %>

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 M.

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 %>

<%= bes.bes_displayname %> <%= bes.bes_phonenumber %> <%= import.prov_service_number %> <% end %>

<% end %>
<% end %>

Thanks!

On 23 Jan 2008, at 00:18, Jeff M. wrote:

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

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 M. [email protected]
wrote:

<% end %>
<% end %>

Thanks!

Posted via http://www.ruby-forum.com/.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs