定义我的自定义设计身份验证策略会引发'load_missing_constant'错误

时间:2012-10-03 04:06:59

标签: ruby-on-rails-3 devise

在我的应用程序中,我正在尝试定义自定义策略,但它会引发一些错误......这就是我正在做的事情:

# myrailsapp/lib/devise/strategies
require 'devise/strategies/database_authenticatable'

module Devise
  module Strategies
    class CustomAuth < Devise::Strategies::DatabaseAuthenticatable
      def valid?
        Rails.logger.info("\n\nIn CustomAuth.valid\n\n")
        true
      end
      def authenticate!
        Rails.logger.info("\n\nCalled My Authenticate!\n\n")
        super
      end
    end
  end
end

Warden::Strategies.add(:custom_auth, Devise::Strategies::CustomAuth)

# config/initializer.rb
config.warden do |manager|
  # manager.strategies.add(:custom_auth, Devise::Strategies::CustomAuth)
  manager.default_strategies(:scope => :user).unshift :custom_auth
end

当我尝试运行时,我收到此错误:

/usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:490:in load_missing_constant': Expected app/helpers/custom_auth.rb to define CustomAuth (LoadError) from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:181:in const_missing'     来自/usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in each' from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in const_missing'     来自/usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:501:in load_missing_constant' from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:181:in const_missing'     来自/usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in each' from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in const_missing'     来自/usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:501:in load_missing_constant' from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:181:in const_missing'     来自/usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in each' from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:179:in const_missing'     来自/home/rjain/src/qbol/tapp/config/initializers/devise.rb:212

现在,当我将同一个文件移动到我的app / helpers目录时,我得到了同样的错误,但是如果我删除了模块设计和模块策略,事情就开始起作用了。两个问题:

  1. 如何确保我可以在lib / devise / strategies文件夹中创建文件?
  2. 如何让它工作,以便我可以在Devise :: Strategies模块中使用它,如上所述?

0 个答案:

没有答案