# String keys in hash

**URL:** <https://www.ruby-forum.com/t/string-keys-in-hash/55311>\
**Category:** Rails\
**Created:** [March 19, 2006, 3:09pm UTC](https://www.ruby-forum.com/t/string-keys-in-hash/55311 "2006-03-19T15:09:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![konlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@konlin](https://www.ruby-forum.com/u/konlin)\
**Post date:** [March 19, 2006, 3:09pm UTC](https://www.ruby-forum.com/t/string-keys-in-hash/55311/1 "2006-03-19T15:09:05Z")

</div>

Hi all,

My 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\_parameters](http://address.com?id=dwNKiItvcyrQ5sycnIhmJablDfXsc9tshaGIVyNIei7.e7&some_other_parameters)

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. removed\_email\_address@domain.invalid  
Kinetic Organism Normally for Logical Infiltration and Nullification,

```
      "Day after day, love turns grey
       Like the skin of a dying man"

```

---

<div class="post-metadata">

**Author:** ![konlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@konlin](https://www.ruby-forum.com/u/konlin)\
**Post date:** [March 19, 2006, 3:59pm UTC](https://www.ruby-forum.com/t/string-keys-in-hash/55311/2 "2006-03-19T15:59:56Z")

</div>

Hi –

On Sun, 19 Mar 2006, Konlin wrote:

> ```
> {:partner_id => 0,
> 
> ```
> 
> 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?

They’re not the same; one of them has double quotation marks and the  
other doesn’t. The string:

```
abc

```

and the string

“abc”

do not make for the same hash key.

David

–  
David A. Black (removed\_email\_address@domain.invalid)  
Ruby Power and Light, LLC ([http://www.rubypowerandlight.com](http://www.rubypowerandlight.com))

“Ruby for Rails” chapters now available  
from Manning Early Access Program! [Ruby for Rails](http://www.manning.com/books/black)

---

<div class="post-metadata">

**Author:** ![konlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@konlin](https://www.ruby-forum.com/u/konlin)\
**Post date:** [March 19, 2006, 4:09pm UTC](https://www.ruby-forum.com/t/string-keys-in-hash/55311/3 "2006-03-19T16:09:04Z")

</div>

On Sun, Mar 19, 2006 at 03:08:28PM +0100, Konlin wrote:

> poll\_id = ‘"’ + params[‘id’] + ‘"’  
> What are those ‘"’ + … + ‘"’ for? You are already passing a  
> string when you do params[‘id’] so this would be enough:

poll\_id = params[‘id’]  
@codes[poll\_id]

or just: @codes[params[‘id’]]

---

<div class="post-metadata">

**Author:** ![konlin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/7c8e57/32.png) [@konlin](https://www.ruby-forum.com/u/konlin)\
**Post date:** [March 19, 2006, 4:19pm UTC](https://www.ruby-forum.com/t/string-keys-in-hash/55311/4 "2006-03-19T16:19:05Z")

</div>

Hi KN,

W Twoim li¶cie datowanym 19 marca 2006 (16:08:46) mo¿na  
przeczytaæ:  
K\> What are those ‘"’ + … + ‘"’ for? You are already passing a  
K\> string when you do params[‘id’] so this would be enough:  
K\>  
K\> poll\_id = params[‘id’]  
K\> @codes[poll\_id]

K\> or just: @codes[params[‘id’]]

You’re right. Thanks for answer, I’m a very beginning programmer 🙂

–  
K.O.N.L.I.N. removed\_email\_address@domain.invalid  
Kinetic Organism Normally for Logical Infiltration and Nullification,

```
      "Is this not what you expected to see?"
```
