Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
String keys in hash
Konlin
3/19/2006 2:10:00 PM
Hi all,
My rails app is going to count sth based on poll id in the url. The url
looks like:
http://address.com?id=dwNKiItvcyrQ5sycnIhmJablDfXsc9tshaGIVyNIei7.e7&some_other_...
In a controller, I've created a hash where the keys are the ids:
@codes = {
'dwNKiItvcyrQ5sycnIhmJablDfXsc9tshaGIVyNIei7.e7' =>
{:partner_id => 0,
:partner_name => 'sth',
:page_number => 1},
...
}
Then i do:
poll_id = '"' + params['id'] + '"'
The problem is, @codes[poll_id] returns nil.
Otherwise, @codes["dwNKiItvcyrQ5sycnIhmJablDfXsc9tshaGIVyNIei7.e7"]
works ok. What am I doing wrong if the keys are the same and explicite
string works while variable doesn't?
Can you explain me that and write how to solve that problem?
Thanks in advance, greetz
--
K.O.N.L.I.N. konlin@post.pl
Kinetic Organism Normally for Logical Infiltration and Nullification,
"Day after day, love turns grey
Like the skin of a dying man"
1 Answer
Scott
3/19/2006 3:10:00 PM
0
Why are you wrapping params['id'] in double quotes? If params['id'] is
already equal to your key in @codes, you can just use:
@codes[params['id']]
-Scott
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
String keys in hash
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password