2011-08-18 37 views
2

爲什麼錯誤?const_missing':未初始化的常量Rack :: IpRestrictor(NameError)

這裏的設置:

配置/初始化/ rack_ip_restrictor.rb

Rack::IpRestrictor.configure do 
    respond_with [403, {'Content-Type' => 'text/html'}, ''] 

    ips_for :test do 
    add '127.0.0.1' 
    add '127.0.0.2/8' 
    end 

    restrict /^\/admin/, '/admin', :only => :test 
end 

的config/application.rb中

class Application < Rails::Application 
    ... 
    config.middleware.use Rack::IpRestrictor.middleware 
    ... 
    end 

/lib/rack_ip_restrictor.rb

require 'ipaddr' 
require 'active_support/core_ext/array/extract_options' 

# namespace Rack 
module Rack 
    # namespace IpRestrictor 
    module IpRestrictor 
    class << self 
     attr_reader :config 

     # @see Config#initialize 
     def configure(&block) 
     @config = IpRestrictor::Config.new 
     @config.instance_eval &block 
     end 

     # Rack middleware 
     # @return [Middleware] The configured plug & play Rack middleware 
     def middleware 
     IpRestrictor::Middleware 
     end 
    end 
    end 
end 

require 'rack_ip_restrictor/ip_group' 
require 'rack_ip_restrictor/middleware' 
require 'rack_ip_restrictor/config' 
require 'rack_ip_restrictor/restriction' 

任何想法爲什麼rails找不到Rack :: IpRestrictor?

謝謝

+0

試圖將此應用程序集成到我的應用程序W/O使用寶石,因爲我需要做很多定製--- https://github.com/phatworx/rack_ip_restrictor – AnApprentice

回答

0

你不需要此文件在任何地方。這就是爲什麼它找不到常數。在lib目錄中的文件不會自動加載到Rails 3.手動需要這個文件。

相關問題