hash problem any ideas ?

on controller i have this:

ldaphash = {}

ldap.search( :base => treebase, :filter => filter ) do |entry|

email = entry[:mail].to_s
uid = entry[:uid].to_s
fullname = entry[:cn].to_s
fullname = Iconv.iconv("ISO-8859-1", "UTF-8", fullname)
@fullname = fullname

if email != '' && uid != '' then
#render :text => "#{fullname} (#{email})"
ldaphash["name"] = "#{fullname}"
ldaphash["email"] = "#{email}"
ldaphash["uid"] = "#{uid}"
end
end

now on the view page I try to access that hash.

<% ldaphash.each_pair do {key,val} %>
<%= "#{key} => #{val}" %>
<% end %>

Since I am total noob with these hashes on ruby any ideas ?

on controller i have this:

ldaphash = {}

ldap.search( :base => treebase, :filter => filter ) do |entry|

email = entry[:mail].to_s
uid = entry[:uid].to_s
fullname = entry[:cn].to_s
fullname = Iconv.iconv("ISO-8859-1", "UTF-8", fullname)
@fullname = fullname

if email != '' && uid != '' then
#render :text => "#{fullname} (#{email})"
ldaphash["name"] = "#{fullname}"
ldaphash["email"] = "#{email}"
ldaphash["uid"] = "#{uid}"
end
end

now on the view page I try to access that hash.

<% ldaphash.each_pair do {key,val} %>
<%= "#{key} => #{val}" %>
<% end %>

Since I am total noob with these hashes on ruby any ideas ?

If you want something in your controller to magically appear in your
views you need to be using instance variables (ie @ldaphash). And the
last bit should of course be

ok i did this on controller:

@ldaphash = ldaphash

and on view i did added this one:

<% ldaphash.each_pair do |key,val| %>
<%= "#{key} => #{val}" %>
<% end %>

now I get error:

undefined local variable or method `ldaphash' for #<ActionView::Base:
0xb76bd0c0>

ok i did this on controller:

@ldaphash = ldaphash

and on view i did added this one:

<% ldaphash.each_pair do |key,val| %>
<%= "#{key} => #{val}" %>
<% end %>

now I get error:

undefined local variable or method `ldaphash' for #<ActionView::Base:
0xb76bd0c0>

It's still an instance variable in the view, so it needs to be
@ldaphash.each_pair

ok now i get error

You have a nil object when you didn't expect it!

view is now

<% @ldaphash.each_pair do |key,val| %>
<%= "#{key} => #{val}" %>
<% end %>

If I create simple file like this test.rb

ldaphash = { }

ldap.search( :base => treebase, :filter => filter ) do |entry|

email = entry[:mail].to_s
uid = entry[:uid].to_s
fullname = entry[:cn].to_s
fullname = Iconv.iconv("ISO-8859-1", "UTF-8", fullname)
@fullname = fullname

if email != '' && uid != '' then
ldaphash["name"] = "#{fullname}"
ldaphash["email"] = "#{email}"
ldaphash["uid"] = "#{uid}"
end

ldaphash.each_pair do |key, val|
puts "#{key} => #{val}"
end

and run it then it works on command line but not on the web ?

ok now I got something to print but only the last item on the hash ??
weird ... any clues ?