# Rails - Hashes

**URL:** <https://www.ruby-forum.com/t/rails-hashes/95304>\
**Category:** Ruby\
**Created:** [May 27, 2006, 8:02am UTC](https://www.ruby-forum.com/t/rails-hashes/95304 "2006-05-27T08:02:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_DSKraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@Paul\_DSKraus](https://www.ruby-forum.com/u/Paul_DSKraus)\
**Post date:** [May 27, 2006, 8:02am UTC](https://www.ruby-forum.com/t/rails-hashes/95304/1 "2006-05-27T08:02:06Z")

</div>

I am trying to iterate over a hash but it only displays ‘#’ for my key.  
I know this is not the case because it outputs the correct number of  
lines  
based on how many keys I have. If it were trully ‘#’ it would only print  
one  
line.

Here is the code that is producing the output…  
\<% @payment.batch.each do|key,value| %\>

- \<%=key%\> -\> \<%=value%\>
  
\<% end %\>

here is my output …

- 
# -\> 1
- 
# -\> 1

Here is the code that builds the hash…  
Controller…  
def add\_invoice  
@payment = find\_payment  
@invoice = Invoice.find(params[:id])  
@payment.add\_invoice(@invoice)  
end  
def find\_payment  
session[:payment] ||= Payment.new  
end

and the class…  
class Payment  
include Reloadable  
attr\_reader :batch

def initialize  
@batch = {}  
end

def add\_invoice(invoice)  
unless @batch[invoice]  
@batch[invoice] = 1  
end  
end  
end

TIA,  
Paul

---

<div class="post-metadata">

**Author:** ![Paul\_DSKraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@Paul\_DSKraus](https://www.ruby-forum.com/u/Paul_DSKraus)\
**Post date:** [May 27, 2006, 8:11am UTC](https://www.ruby-forum.com/t/rails-hashes/95304/2 "2006-05-27T08:11:16Z")

</div>

Paul D. Kraus wrote:

> here is my output …
> 
> - 
> # -\> 1
> - 
> # -\> 1

What does view|source on the resulting Web page show you?

I’m betting key is an object with no useful default to\_s.

–  
James B.

“In physics the truth is rarely perfectly clear, and that is certainly  
universally the case in human affairs. Hence, what is not surrounded  
by  
uncertainty cannot be the truth.”

- R. Feynman

---

<div class="post-metadata">

**Author:** ![Paul\_DSKraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@Paul\_DSKraus](https://www.ruby-forum.com/u/Paul_DSKraus)\
**Post date:** [May 27, 2006, 8:20am UTC](https://www.ruby-forum.com/t/rails-hashes/95304/3 "2006-05-27T08:20:30Z")

</div>

> What does view|source on the resulting Web page show you?
> 
> I’m betting key is an object with no useful default to\_s.

Good Call …

- # -\> 1

Ok so why is the key getting set to this.

```
@invoice = Invoice.find(params[:id])
@payment.add_invoice(@invoice)

```

are the lines that get the “key” params[:id] is just the id number from  
a  
row in result set. Or more accuratly its just this from the url…  
[http://xxx.xxx.xxx.xxx:3000/selection/add\_invoice/4](http://xxx.xxx.xxx.xxx:3000/selection/add_invoice/4)

This is my very first attempt at rails and ruby is pretty new to me as  
well.  
but shouldn’t params[:id] = ‘4’

Paul

---

<div class="post-metadata">

**Author:** ![Paul\_DSKraus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ed655f/32.png) [@Paul\_DSKraus](https://www.ruby-forum.com/u/Paul_DSKraus)\
**Post date:** [May 27, 2006, 8:20am UTC](https://www.ruby-forum.com/t/rails-hashes/95304/4 "2006-05-27T08:20:36Z")

</div>

> This is my very first attempt at rails and ruby is pretty new to me as  
> well.  
> but shouldn’t params[:id] = ‘4’

Never Mind = its getting “Invoice.find”

Thanks for the help.
