首页 > 解决方案 > 无法使用自定义设计策略

问题描述

我使用 devise 在我的 rails 应用程序上添加了一个身份验证层。我必须设置 LDAP 身份验证。因此,我创建了自己的策略,我从字面上遵循了这篇wiki 文章。但是,我收到了这个错误:

11: from /home/mcdostone/X/app/models/user.rb:3:in `<main>'
10: from /home/mcdostone/X/app/models/user.rb:4:in `<class:User>'
...
/home/mcdostone/.rvm/gems/ruby-2.5.1/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/active_support.rb:74:in `block in load_missing_constant': uninitialized constant Devise::Models::LdapAuthenticatable (NameError)
class User < ApplicationRecord
  devise :ldap_authenticatable
end

标签: ruby-on-railsdevise

解决方案


看起来那个wiki页面已经过时了。您现在需要一个LdapAuthenticatable模块Devise::Models以及Devise::Strategies.

config/initializers/ldap_authenticatable.rb

module Devise
  module Models
    module LdapAuthenticatable
      extend ActiveSupport::Concern
    end
  end

  module Strategies
    class LdapAuthenticatable < Authenticatable
      ... same as before ...
    end
  end
end

我真的建议您改用此gem,因为您需要进行许多调整才能使其正常工作。


推荐阅读