Home arrow Ruby-on-Rails arrow Page 3 - Load Balancing Databases with Rails
RUBY-ON-RAILS

Load Balancing Databases with Rails


In this conclusion to a five-part series on databases and Ruby-on-Rails, you'll learn how a number of databases handle load balancing and high availability issues. This article is excerpted from chapter four of the book Advanced Rails, written by Brad Ediger (O'Reilly; ISBN: 0596510322).Copyright © 2008 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 3 stars3 stars3 stars3 stars3 stars / 2
February 04, 2010
TABLE OF CONTENTS:
  1. · Load Balancing Databases with Rails
  2. · PostgreSQL
  3. · LDAP
  4. · Authenticating with LDAP

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Load Balancing Databases with Rails - LDAP
(Page 3 of 4 )

 

LDAP, the Lightweight Directory Access Protocol, is a database system optimized for user directory information. It is most often used in large organizations, integrated with the enterprise authentication and email systems. However, it is a database in its own right. We do not have space to cover LDAP in detail, but there are many resources available for working with LDAP in Rails.

ActiveLDAP

The ActiveLDAP library (http://ruby-activeldap.rubyforge.org/) is an almost drop-in replacement for ActiveRecord that uses LDAP instead of an RDBMS as a backend. To use it from Rails, set up a configuration file, config/ldap.yml, as follows:

  development:
    host: (ldap server name)
   
port: 389
    base: dc=mycompany,dc=com
   
password: my_password

  production:
   
...

Then, at the bottom of config/environment.rb, set up the connection:

  ldap_path = File.join(RAILS_ROOT,"config","ldap.yml")
  ldap_config = YAML.load(File.read(ldap_path))[RAILS_ENV]
  ActiveLDAP::Base.establish_connection(ldap_config)

To set up ActiveLDAP, just subclass ActiveLDAP::Base and set the LDAP mapping on a class-by-class basis:

  class Employee < ActiveLDAP::Base
    ldap_mapping :prefix => "ou=Employees"
  end

LDAP queries can then be executed using the class methods on ActiveLDAP::Base:

  @dan = Employee.find :attribute => "cn", :value => "Dan"


blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form
- Ruby on Rails Templates and Layouts
- Action Pack Controller Creation
- Writing an Action Pack Controller

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials