我的Rails应用程序中有两种类型的设计身份验证。一个是LDAP,另一个是数据库身份验证。我想根据用户选项制作它。我尝试了将该选项作为函数并传递值的一些事情。但它显示我错误:uninitialized constant Devise::Models::Authentication (NameError)
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :authentication, :registerable,
:recoverable, :rememberable, :trackable, :validatable
def authentication
flag=1
if flag == true
auth = "database_authenticatable"
else
auth = "ldap_authenticatable"
end
"#{auth}"
end
end
现在我想让这段代码工作,之后我会自己添加flag选项。提前谢谢。
答案 0 :(得分:3)
class User < ActiveRecord::Base
if flag == 1
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable
else
devise :ldap_authenticatable, :registerable,
:recoverable, :rememberable, :trackable
end
end
答案 1 :(得分:0)
使用类似的东西:
devise *devise_options
def devise_options
[:authentication,
:registerable,
:recoverable,
:rememberable,
:trackable,
:validatable,
(flag ? :database_authenticatable : :ldap_authenticatable)]
end