ruby-on-rails - 根据用户的选择在设计中设置身份验证选项

标签 ruby-on-rails devise ldap

我的 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

现在我想让这段代码工作,然后我将自己添加标志选项。提前致谢。

最佳答案

class User < ActiveRecord::Base if flag == 1 devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable else devise :ldap_authenticatable, :registerable, :recoverable, :rememberable, :trackable end end

关于ruby-on-rails - 根据用户的选择在设计中设置身份验证选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28780047/

相关文章:

javascript - 设置选择选项的默认值

ruby-on-rails - 常规 ActionController::InvalidAuthenticityToken 异常 - Rails

ruby-on-rails - 使用 :token_authenticable 的设计的自定义身份验证策略

ruby-on-rails - 无法启动新的Rails服务器-sqlite.3h丢失

ruby-on-rails - POST json 到 Rails 服务器

ruby-on-rails - 来自 URL 的 Ruby on Rails 和 JSON 解析器

ruby-on-rails - rails : Adding an admin role using devise who can see all the users

python-ldap -- 在 Active Directory 中创建用户 -- 问题 2003 (BAD_ATT_SYNTAX) cn 和 DN

windows - lastLogonTimeStamp 属性的 1601/01/01

mysql - 如何在 Liferay 6.2 上将 LDAP 设置为永久