I'm running rails 3.1 with latest Devise and ldap plugin. I have exchanged the default behaviour of using email address and now uses the uid attribute in Novell eDir as my userfield.
I can log in, I get redirected based on root route etc.
What I am now struggeling with is to get email and a custom attribute named category from my ldap and inserted into the database. Im trying to get the before_save working.
class User < ActiveRecord::Base
before_save :get_ldap_email
before_save :get_ldap_category
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :ldap_authenticatable, :rememberable, :trackable
# Setup accessible (or protected) attributes for your model
attr_accessible :uid, :category, :email, :password, :password_confirmation, :remember_me
def get_ldap_email
self.email = Devise::LdapAdapter.get_ldap_param(self.uid, "mail")
end
def get_ldap_category
self.category = Devise::LdapAdapter.get_ldap_param(self.uid, "category")
end
end
Im probably dumb but I cant get this to work. I get the following output from my view at login:
NoMethodError in Devise::SessionsController#create
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
Rails.root: /home/ntr/Dropbox/source/devise
Application Trace | Framework Trace | Full Trace
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"jljpH9bUXrPeBVy4jKnJoAfeuO/EiF0YxRqxm07VF5w=",
"user"=>{"uid"=>"ntr",
"password"=>"[FILTERED]",
"remember_me"=>"0"},
"commit"=>"Logga in"}
Show session dump
Show env dump
Response
Headers:
None
What am I doing wrong? Would love to get some help with this!
Best regards //Roger
I'm not sure is it help you, but you can use it like that:
This happens when your search fetches few results instead one and you'll get nil valuse Here is a hack which always return array die to ldap nature: in the file config/initializer/devise.rb add following patch:
Look more at https://github.com/cschiewek/devise_ldap_authenticatable/issues/69 and compare patch with original code to understand.