Skip to content

Instantly share code, notes, and snippets.

@ged
Forked from pbruna/show.html.erb
Created January 19, 2012 23:07
Show Gist options
  • Save ged/1643614 to your computer and use it in GitHub Desktop.
Save ged/1643614 to your computer and use it in GitHub Desktop.
Treequel adding to many extensions
class OrganizationalUnitsController < ApplicationController
def show
@organizational_unit = @directory.search( params[:id], :base )
end
end
require 'treequel/model'
require 'treequel/model/objectclass'
module OrganizationalUnit
extend Treequel::Model::ObjectClass
extend Global::Class
model_class Treequel::Model
model_bases "o=company,c=cl"
model_objectclasses :organizationalUnit
# id is the dn off the entry we are looking
def self.find(id)
# (assuming id="uid=foobar,o=company,c=cl")
attrs, base = id.split(/,/, 2)
# => ['uid=foobar', 'o=company,c=cl']
# 'uid=foobar' is equivalent to { :uid => 'foobar' }
# and the #from method can reset the base for one search (without resetting it
# for the whole model):
filter(attrs).from(base).first
end
end
<div style="float: left;">
<p>
<%= @organizational_unit.description_text %><br/>
<%= @organizational_unit.extensions.size %>
</p>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment