[英]const_missing': uninitialized constant Rack::IpRestrictor (NameError)
Why the error? 为什么会出错?
Here's the setup: 设置如下:
config/initializers/rack_ip_restrictor.rb config / initializers / 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 config / application.rb
class Application < Rails::Application
...
config.middleware.use Rack::IpRestrictor.middleware
...
end
/lib/rack_ip_restrictor.rb /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'
Any idea why rails can't find Rack::IpRestrictor ? 知道为什么Rails找不到Rack :: IpRestrictor吗?
Thanks 谢谢
You're not requiring this file anywhere. 您在任何地方都不需要此文件。 That is why it cannot find the constant. 这就是为什么它找不到常量。 Files in the lib
directory are not automatically loaded in Rails 3. Require this file manually. lib
目录中的文件不会自动加载到Rails 3中。手动需要此文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.