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 ? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12 Feb 2008, at 14:06, KTU wrote:> > 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> <% ldaphash.each_pair do |key,val| %> > <%= "#{key} => #{val}" %> > <% end %>> > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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> On Feb 12, 4:17 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12 Feb 2008, at 14:06, KTU wrote: > > > > > > > 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 > > > <% ldaphash.each_pair do |key,val| %> > > <%= "#{key} => #{val}" %> > > <% end %>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 12 Feb 2008, at 14:27, KTU wrote:> > 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> > > > > On Feb 12, 4:17 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On 12 Feb 2008, at 14:06, KTU wrote: >> >> >> >> >> >>> 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 >> >>> <% ldaphash.each_pair do |key,val| %> >>> <%= "#{key} => #{val}" %> >>> <% end %> > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 ? On Feb 12, 4:36 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12 Feb 2008, at 14:27, KTU wrote: > > > > > 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 > > > > > On Feb 12, 4:17 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On 12 Feb 2008, at 14:06, KTU wrote: > > >>> 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 > > >>> <% ldaphash.each_pair do |key,val| %> > >>> <%= "#{key} => #{val}" %> > >>> <% end %>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
ok now I got something to print but only the last item on the hash ?? weird ... any clues ? On Feb 12, 4:47 pm, KTU <ketuo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 ? > > On Feb 12, 4:36 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On 12 Feb 2008, at 14:27, KTU wrote: > > > > 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 > > > > On Feb 12, 4:17 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > >> On 12 Feb 2008, at 14:06, KTU wrote: > > > >>> 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 > > > >>> <% ldaphash.each_pair do |key,val| %> > > >>> <%= "#{key} => #{val}" %> > > >>> <% end %>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---