2011-08-18 3 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 

설정/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' 

레일이 Rack :: IpRestrictor를 찾을 수없는 이유는 무엇입니까?

감사합니다.

+0

내 응용 프로그램에 이것을 사용하지 않고 보석을 사용하여 맞춤 설정을 많이해야하는 경우 --- https://github.com/phatworx/rack_ip_restrictor – AnApprentice

답변

0

이 파일을 어디에도 요구하지 않습니다. 그것이 상수를 찾을 수없는 이유입니다. lib 디렉토리의 파일은 Rails 3에 자동으로로드되지 않습니다.이 파일을 수동으로 요구하십시오.

관련 문제