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
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/
long story short: s/=/==/ will do the trick
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/
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])
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.
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’
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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.