# Two ActiveLDAP questions

**URL:** <https://www.ruby-forum.com/t/two-activeldap-questions/100696>\
**Category:** Ruby\
**Created:** [February 3, 2006, 6:55pm UTC](https://www.ruby-forum.com/t/two-activeldap-questions/100696 "2006-02-03T18:55:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 3, 2006, 6:55pm UTC](https://www.ruby-forum.com/t/two-activeldap-questions/100696/1 "2006-02-03T18:55:38Z")

</div>

Two questions about ActiveLDAP:

* * *

Question #1:  
When I create an ActiveLDAP::Base object, the dn attribute used in the  
mapping does not get an accessor method. For example:

#!/usr/local/bin/ruby  
require ‘activeldap’

class Person \< ActiveLDAP::Base  
ldap\_mapping :dnattr =\> ‘uid’, :prefix =\> ‘ou=People’  
end

ActiveLDAP::Base.connect(  
:host =\> ‘localhost’,  
:port =\> 40003,  
:base =\> ‘dc=cusys,dc=edu’,  
:bind\_format =\> ‘uid=admin,dc=cusys,dc=edu’,  
:password\_block =\> Proc.new { ‘SecretWord’ },  
:allow\_anonymous =\> false  
)

for person in Person.find\_all(:attribute =\> ‘givenName’, :value =\>  
‘Puppy’, :objects =\> true) do  
puts "DN: " + person.dn  
puts "CN: " + [person.cn](http://person.cn)[0]  
puts "UID: " + person.uid[0]  
end

##END CODE

There is definitely a uid attribute in the LDAP. But when I run the  
above, I get this:

DN: uid=PBarksalot,ou=People,dc=cusys,dc=edu  
CN: Puppy Barksalot  
/usr/local/lib/ruby/site\_ruby/1.8/activeldap/base.rb:846:in  
`method_missing': undefined method `uid’ for #Person:0xb7565dac  
(NoMethodError)  
from ./test.rb:24  
from ./test.rb:21:in `each’  
from ./test.rb:21

When I do a person.inspect, I see a data member called “nil” that  
points to the string that should be in “uid”:

…@data={“cn”=\>[“Puppy Barksalot”], nil=\>[“PBarksalot”],  
“sn”=\>[“Barksalot”], “objectClass”=\>[“top”, “person”,  
“organizationalPerson”, “inetorgperson”]}\>

Can anyone help me out?

* * *

Question #2:

I’m trying to use ActiveLDAP in Rails, just like the above but with the  
relevant code snippets distributed to config, models, views and so on.  
I can get my application to query the LDAP successfully; a  
person.inspect shows all the attributes’ values are returned. However,  
none of the accessor methods are created. The collection that should  
hold them, @attr\_methods, is empty.

Has anyone seen/solved this?

Thanks.

Justin
