Small conditional statement not working

While I’m pulling data out of a form I’m trying to do this

unless v[:state_id] = 0 # Should be interpreted as the state_id is the
number zero.

However it doesn’t seem to be working for some reason.

The conditional about it is
unless v[:state_id].blank? # this conditional works
unless v[:state_id] = 0

I’ve tried single quotes, double quotes and nothing seems to be stopping
it.

Any obvious reasons ?
Stuart

hi stuart!

Dark A. [29.10.2006 22:05]:

While I’m pulling data out of a form I’m trying to do this

unless v[:state_id] = 0 # Should be interpreted as the state_id
is the number zero.
what you’re actually doing here is assigning (=) the value 0 to
your variable (returning that value, which in ruby is true), while
what you’d rather want is testing for equality (==).

long story short: s/=/==/ will do the trick :wink:

cheers
jens


Jens W., Dipl.-Bibl. (FH)
prometheus - Das verteilte digitale Bildarchiv für Forschung & Lehre
An St. Laurentius 4, 50931
KölnTel.: +49 (0)221 470-6668, E-Mail: [email protected]
http://www.prometheus-bildarchiv.de/

n 10/29/06, jens wille [email protected] wrote:

your variable (returning that value, which in ruby is true), while
what you’d rather want is testing for equality (==).

Well I did try == 0 , and basically layed there like a dead mouse.

long story short: s/=/==/ will do the trick :wink:

what is this ? is this a typo , because this won’t parse .

Stuart

cheers

Dark A. [29.10.2006 22:19]:

long story short: s/=/==/ will do the trick :wink:
what is this ? is this a typo , because this won’t parse .
well, it just means that you have to substitute the single = by ==.

however, you said that your data came out of a form which probably
makes them strings, so you might try:

v[:state_id] == ‘0’

or

v[:state_id].to_i == 0

hth
jens


Jens W., Dipl.-Bibl. (FH)
prometheus - Das verteilte digitale Bildarchiv für Forschung & Lehre
An St. Laurentius 4, 50931
KölnTel.: +49 (0)221 470-6668, E-Mail: [email protected]
http://www.prometheus-bildarchiv.de/

On 10/29/06, jens wille [email protected] wrote:

v[:state_id] == ‘0’

or

v[:state_id].to_i == 0

hth
jens

Well, I give up , cause none of these plus all the one’s I’ve tried
don’t
seem to make a difference.

Stuart

unless v[:state_id] == 0
will return true only if v[:state_id] does not equal zero, is that what
you are wanting to do? Or do you want it to check if state_id is not
set? (unless v[:state_id])

On 10/29/06, jdswift [email protected] wrote:

unless v[:state_id] == 0
will return true only if v[:state_id] does not equal zero, is that what
you are wanting to do? Or do you want it to check if state_id is not
set? (unless v[:state_id])

If the state_id IS 0 (meaning the number zero). So I don’t think it
should
be == ,
I think it should be = , but I did a != 0 and that really mucked things
up.

Stuart

Exactly what are you trying to do?

do something ‘unless v[:state_id] is zero’
do something ‘unless “setting v[:state_id] to zero evalutates to true”’
do something ‘unless v[:state_id] is not zero’

On 10/30/06, Mike [email protected] wrote:

Exactly what are you trying to do?

do something ‘unless v[:state_id] is zero’ <-------------- Yes this one.

Stuart

do something ‘unless “setting v[:state_id] to zero evalutates to true”’

you are wanting to do? Or do you want it to check if state_id is not

Stuart

Dark A. wrote:

On 10/30/06, Mike [email protected] wrote:

Exactly what are you trying to do?
do something ‘unless v[:state_id] is zero’ <-------------- Yes this one.

do_something unless v[:state_id] == 0

or

unless v[:state_id] == 0
do_something
end

I suspect that your values are not what you think they are, or that you
are having trouble properly testing what is going on. If you are
testing for equality, you definitely, absolutely, always want a double
equals sign. That you were confused about that makes me think that your
life might become easier if you read a beginner’s book on programming
in Ruby.

On 10/30/06, Phrogz [email protected] wrote:

or
life might become easier if you read a beginner’s book on programming
in Ruby.

I’m not sure what is meant by equality but if I remember correctly from
reading a beginner’s book,
equality is not the same as comparing one value to the next.
All I am trying to ask (Ruby) is the value in v[:state_id] zero. In
that
case I believe one set of equal signs is correct.
Let me know if I’m wrong or if there is some misunderstanding here.

Stuart