Now I have function which loops thru 100 users and I would need to
append them to end of that hash ie.
some_hash should start to look like this:
some_hash = {"name" => "tom", "uid"="100", "mail" = "tom.dot.com",
"name" => "diana", "uid="101", "mail" => "diana.dot.com", .... and
so }
I tried has merge but since keys are same for all entries ie. (name,
uid, mail) it only replaced current value
and I ended up having a hash with only last value on that loop.
If this is not possible whats the way to dynamically create such key,
value pairs so I can loop then thru
and check if key value is uid (or email or name) and then do
whatever ...
Now I have function which loops thru 100 users and I would need to
append them to end of that hash ie.
some_hash should start to look like this:
some_hash = {"name" => "tom", "uid"="100", "mail" = "tom.dot.com",
"name" => "diana", "uid="101", "mail" => "diana.dot.com", .... and
so }
I tried has merge but since keys are same for all entries ie. (name,
uid, mail) it only replaced current value
and I ended up having a hash with only last value on that loop.
that's pretty much the definition hash: a key maps to a unique value.
Do you in fact just want an array of hashes?
well im a noob but looks im getting closer. what i have now is
<% @collection.each do |key,val| %>
KEY: <%= key %> VAL: <%= val %><br>
<% end %>
The members of the collection are hashes, but @collection isn't. You need to iterate over @collection, which yields you the hashes, and then you need to iterate over those to print the key value pairs.
There's probably not much value in doing this as opposed to iterating over the entries returned by ldap.search
well ldapsearch works in controller only and from there I need to pass
data to the view. This is too complicated for me since there are no
good
examples on the net. I just do big array and go those one by one thru.
well ldapsearch works in controller only and from there I need to pass
data to the view. This is too complicated for me since there are no
good
examples on the net. I just do big array and go those one by one thru.
Creating some collection in a controller and then iterating over that
in a view is something that any tutorial app will cover. Sure most of
those collections would be ActiveRecord objects rather than ldap
thingies, but that doesn't make any difference.
All you need to do is
@ldap_entries = ldap.search( :base => treebase, :filter => filter )
in your controller, and
<% @ ldap_entries.each do |entry| %>
...
<% end %>
Or <%= render :partial => 'entry', :collection => @ldap_entries %>
and then have _entry.html.erb that looks something like