Net::LDAP::LdapError: no connection to server

449 views
Skip to first unread message

Gustaf Lindqvist

unread,
Feb 27, 2013, 9:42:51 AM2/27/13
to ruby...@googlegroups.com
Trying to establish a connection from a module in Rails and get no connection to server. I have tested the same code outside Rails and it works fine.

#!/usr/bin/ruby -w
require 'rubygems'
require 'net-ldap'

module Foo
  module Bar
    class User

      attr_reader :ldap_connection

      def initialize
        @@ldap = Net::LDAP.new(:host => "<ip-number>", :port => 389)
        @@treebase = "ou=People, dc=foo, dc=bar"
        username = "cn=Manager"
        password = "password"
        @@ldap.auth username, password

        begin
          if @@ldap.bind
            @ldap_connection = true
          else
            @ldap_connection = false
          end
        rescue Net::LDAP::LdapError
          @ldap_connection = false
        end
      end 
end
end
end

Any ideas why this is failing in Rails. Does net-ldap do any dns lookup that might get wrong inside Rails stack? 


Reply all
Reply to author
Forward
0 new messages