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 …
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
Paul D. Kraus wrote:
here is my output …
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.”
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
This is my very first attempt at rails and ruby is pretty new to me as
well.
but shouldn’t params[:id] = ‘4’
Paul
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.