Im having difficulties setting up my controller to connect to our ldap
server. I've searched around in google and found wikis of snippets of
some code to set ruby ldap. Below is what I currently have but Im
getting "uninitialized constant LDAP" when I try to access the login.
Im not what what Im missing or how to debug this. Any suggestions or
tips is appreciated.

class LoginController < ApplicationController

  #Bind with the main credential and query the full DN of the email
  #given to us as a parameter, then unbind and rebind as the user.
  def self.authenticate(username,password)
    logger.debug("username = " + username)

    ldap_con = initialize_ldap_con(username,password)
    treebase = "DC=domain,DC=domainext"
    mail_filter = Net::LDAP::Filter.eq( "mail", '' )
    op_filter = Net::LDAP::Filter.eq( "objectClass",
"organizationalPerson" )
    dn = :base => treebase, :filter => op_filter &
mail_filter, :attributes=> 'dn') do |entry|
      dn = entry.dn
    login_succeeded = false
    unless dn.empty?
      ldap_con = initialize_ldap_con(dn,password)
      login_succeeded = true if ldap_con.bind
    logger.debug("login_succeeded = " + login_succeeded)

  def self.initialize_ldap_con(user_name, password) {:host => 'hostnamehere', :port => 389, :auth => {
:method => :simple, :username => user_name, :password => password }} )

  def index
     case @request.method
      when :post
        if @session['user'] =

          flash['notice'] = "Login successful"
          redirect_back_or_default :action => "overview"
          @login = @params['user_login']
          @message = "Login unsuccessful"

Here is my embarrasingly simplest-thing-that-could-work:

class LoginTestController < ApplicationController
  def index
    ldap = = 'COSEAD.cose.win2k'
    ldap.port = 389
    ldap.auth 'username@cose.win2k', 'some_test_password'
    if ldap.bind
      # authentication succeeded
      render :text=>'yay'
      # authentication failed
      render :text=>'boo'

That at least makes sure the LDAP part works, then it's simple to build
out the Rails part.