# Ldap application using rails?

**URL:** <https://www.ruby-forum.com/t/ldap-application-using-rails/82923>\
**Category:** Rails\
**Created:** [January 22, 2007, 1:22pm UTC](https://www.ruby-forum.com/t/ldap-application-using-rails/82923 "2007-01-22T13:22:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 22, 2007, 1:22pm UTC](https://www.ruby-forum.com/t/ldap-application-using-rails/82923/1 "2007-01-22T13:22:54Z")

</div>

Hi all,  
I’d like to write an ldap application using rails, but not 100% sure how  
to lay everything out.

there are no models, as the data is all stored in ldap, so would  
everything be done in just the views and controllers?

i’ve previously written an ldap connection app and i had the connection  
class in lib/ldap\_con.rb .

i had “$sessions = {}” in environment.rb, so when a controller created a  
new connection\_object, i stored the session object in that hash - is  
that the right way to do it??

the problem with that was every action in my controllers would need to  
create a new session variable and grab the session, which didn’t seem  
right to me.  
ie each method had:  
@session = $sessions[session.session\_id]

another problem with this is that the ldap\_con.rb file had everything in  
it - all the modify/create/delete methods, as well as connection and  
disconnection methods.

any thoughts on how to go about this?  
thanks for reading.

---

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 22, 2007, 2:53pm UTC](https://www.ruby-forum.com/t/ldap-application-using-rails/82923/2 "2007-01-22T14:53:58Z")

</div>

Hi

Paul PH wrote:

> Hi all,  
> I’d like to write an ldap application using rails, but not 100% sure how  
> to lay everything out.
> 
> there are no models, as the data is all stored in ldap, so would  
> everything be done in just the views and controllers?

Just because you aren’t persisting your data with ActiveRecord doesn’t  
mean that you shouldn’t have models. All of your business logic should  
be in your models. Your controllers should only load enough data for  
your view to present.

---

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 22, 2007, 3:00pm UTC](https://www.ruby-forum.com/t/ldap-application-using-rails/82923/3 "2007-01-22T15:00:22Z")

</div>

bryanl wrote:

> Hi
> 
> Paul PH wrote:
> 
> > Hi all,  
> > I’d like to write an ldap application using rails, but not 100% sure how  
> > to lay everything out.
> > 
> > there are no models, as the data is all stored in ldap, so would  
> > everything be done in just the views and controllers?
> 
> Just because you aren’t persisting your data with ActiveRecord doesn’t  
> mean that you shouldn’t have models. All of your business logic should  
> be in your models. Your controllers should only load enough data for  
> your view to present.

are there any examples out there of how to do this? i’ve no idea how to  
write a model that doesn’t depend on a postgres backend of some sort, so  
i’m pretty stuck.

regarding the session, is a global session hash the right way to store  
and access it?

thanks for the reply.

---

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 22, 2007, 3:21pm UTC](https://www.ruby-forum.com/t/ldap-application-using-rails/82923/4 "2007-01-22T15:21:05Z")

</div>

Hi

> are there any examples out there of how to do this? i’ve no idea how to  
> write a model that doesn’t depend on a postgres backend of some sort, so  
> i’m pretty stuck.
> 
> regarding the session, is a global session hash the right way to store  
> and access it?
> 
> thanks for the reply.

A simple example on how to start this: [Parked at Loopia](http://pastie.caboo.se/34802)

You could create a base class called LdapModels and have your models  
inherit from that so you could share some of the code for accessing  
LDAP.

---

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 22, 2007, 4:44pm UTC](https://www.ruby-forum.com/t/ldap-application-using-rails/82923/5 "2007-01-22T16:44:39Z")

</div>

Paul PH wrote:

> bryanl wrote:
> 
> > Hi
> > 
> > > are there any examples out there of how to do this? i’ve no idea how to  
> > > write a model that doesn’t depend on a postgres backend of some sort, so  
> > > i’m pretty stuck.

Also, take a look at ActiveLDAP -  
[http://wiki.rubyonrails.com/rails/pages/ActiveLDAP](http://wiki.rubyonrails.com/rails/pages/ActiveLDAP)

---

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 22, 2007, 3:58pm UTC](https://www.ruby-forum.com/t/ldap-application-using-rails/82923/6 "2007-01-22T15:58:34Z")

</div>

bryanl wrote:

> Hi
> 
> > are there any examples out there of how to do this? i’ve no idea how to  
> > write a model that doesn’t depend on a postgres backend of some sort, so  
> > i’m pretty stuck.
> > 
> > regarding the session, is a global session hash the right way to store  
> > and access it?
> > 
> > thanks for the reply.
> 
> A simple example on how to start this: [Parked at Loopia](http://pastie.caboo.se/34802)
> 
> You could create a base class called LdapModels and have your models  
> inherit from that so you could share some of the code for accessing  
> LDAP.

thanks for the example. i’ve had a go at doing something like that, but  
not got too far.  
I don’t know where to ‘require…’ my lib/ where to \< Inherit it, or  
anything.

thanks again for the reply, but i think i’m going to give up on this one  
rather than pull more hair out.

either i’ve not read the agile web development and ruby for rails books  
thoroughly enough, or rails just seems to be all about database apps,  
and since i’m not using one it’s just too difficult.

cheers.

---

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 22, 2007, 5:25pm UTC](https://www.ruby-forum.com/t/ldap-application-using-rails/82923/7 "2007-01-22T17:25:52Z")

</div>

Benjamin Ritcey wrote:

> Paul PH wrote:
> 
> > bryanl wrote:
> > 
> > > Hi
> > > 
> > > > are there any examples out there of how to do this? i’ve no idea how to  
> > > > write a model that doesn’t depend on a postgres backend of some sort, so  
> > > > i’m pretty stuck.
> 
> Also, take a look at ActiveLDAP -  
> [Peak Obsession](http://wiki.rubyonrails.com/rails/pages/ActiveLDAP)

i’ve looked at activeldap a little, and that seems even more confusing  
to me.

i’ve made a little bit of progress going about using my own models  
though.  
i have my controller creating a new instance of the model, and the model  
accesses the ldap\_connection.rb lib methods by require  
‘ldap\_connection.rb’.

what STILL baffles me though, is the separation between the model and  
the lib. if i have a search\_for\_user(name) method in my controller, i  
also need a search\_for\_user(name) method in the lib. i don’t understand  
that at all.

thanks.

---

<div class="post-metadata">

**Author:** ![extempore](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6bbea6/32.png) [@extempore](https://www.ruby-forum.com/u/extempore)\
**Post date:** [January 22, 2007, 5:34pm UTC](https://www.ruby-forum.com/t/ldap-application-using-rails/82923/8 "2007-01-22T17:34:47Z")

</div>

Paul PH wrote:

> the lib. if i have a search\_for\_user(name) method in my controller, i  
> also need a search\_for\_user(name) method in the lib. i don’t understand  
> that at all.
> 
> thanks.

Right - ActiveRecord (and ActiveLDAP, to a degree) hides all that away -  
if you’re not going to use them, you’ll need to implement all of those  
functions yourself.
