2013-11-25 100 views
0

我已经创建了一个带有rails4的web应用程序,并且使用devise_ldap_authenticable gem开发了认证系统。 其中我使用用户名登录而不是电子邮件。但我想在我的用户表中存储电子邮件。 我的用户模型是如何在Ruby on Rails应用程序数据库中存储ldap数据?

class User < ActiveRecord::Base 
# Include default devise modules. Others available are: 
# :confirmable, :lockable, :timeoutable and :omniauthable 
#@attr_accessible :email, :password, :password_confirmation 
# not required for LDAP :recoverable, :registerable, :validatable 
devise :ldap_authenticatable, :rememberable, :trackable 

validates_uniqueness_of :email, :allow_blank => true 

before_save :get_ldap_email 

def get_ldap_email 
    self.email = Devise::LDAP::Adapter.get_ldap_param(self.username, "mail") 
end 
end 

但在电子邮件领域的用户表像

`email` = '--- !ruby/array:Net::BER::BerIdentifiedArray\ninternal:\n- !ruby/string:Net::BER::BerIdentifiedString\n str: !binary |-\n cy5naG9zaEBzYW1zdW5nLmNvbQ==\n ber_identifier: 4\nivars:\n :@ber_identifier: 49\n' 

其存储数据我的日志说 LDAP:请求PARAM邮件具有值“[email protected] “]

如何将此值存储到我的用户表中。我在哪里做错了?请帮助我。

回答

0

只需要添加下列那么它完全确定

def get_ldap_email 
    self.email = Devise::LDAP::Adapter.get_ldap_param(self.username, "mail").first 
end 
相关问题