【问题标题】:Cannot start server with "rack-recaptcha" gem无法使用“rack-recaptcha”gem 启动服务器
【发布时间】:2011-03-18 21:58:23
【问题描述】:

我已按照 rack-recaptcha readme 中描述的步骤进行操作。

我已完成所有步骤,而不是“您必须在 gemfile 中要求 'rack-recaptcha'。”

由于以下错误,服务器无法启动:

引导杂种 => Rails 2.3.5 应用程序从 http://127.0.0.1:3001 开始 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in `load_missing_constant' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing' /{path_to_my_project}/config/environment.rb:29 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:111:in `run' /{path_to_my_project}/config/environment.rb:9 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:84 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require' ./script/server:3 /Library/Ruby/Gems/1.8/gems/ruby-debug-ide-0.4.9/lib/ruby-debug-ide.rb:109:in `debug_load' /Library/Ruby/Gems/1.8/gems/ruby-debug-ide-0.4.9/lib/ruby-debug-ide.rb:109:in `debug_program' /Library/Ruby/Gems/1.8/gems/ruby-debug-ide-0.4.9/bin/rdebug-ide:87 /usr/bin/rdebug-ide:19:in `load' /usr/bin/rdebug-ide:19 -e:2:在“加载”中 -e:2 未捕获的异常:未初始化的常量 Rack::Recaptcha

我认为,我跳过的“gemfile”步骤是导致此错误的原因。

但是,我不知道,我应该在哪里寻找提到的“gemfile”?

请帮忙


更新:

environment.rb 正在关注

# Be sure to restart your server when you modify this file

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|
  # Settings in config/environments/* take precedence over those specified here.
  # Application configuration should go into files in config/initializers
  # -- all .rb files in that directory are automatically loaded.

  # Add additional load paths for your own custom dirs
  #config.load_paths += %W( #{RAILS_ROOT}/extras )
  config.load_paths += %W( #{RAILS_ROOT}/public )

  # Specify gems that this application depends on and have them installed with rake gems:install
  # config.gem "bj"
  # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
  config.gem "sqlite3-ruby", :lib => "sqlite3"
  # config.gem "aws-s3", :lib => "aws/s3"
  # NOTE: jquery.js must be updated to the latest version 1.4.2
  # to avoid differences in behaviour of HTML makeup and Rails
  config.gem 'jrails'
  config.gem 'nokogiri
  config.gem 'uuid
  config.gem 'rack-recaptcha', :lib => 'rack/recaptcha'
  config.middleware.use Rack::Recaptcha, :public_key => 'my_secret', :private_key => 'my_secret', :paths => 'http://localhost:3001/my_controller'

  # Only load the plugins named here, in the order given (default is alphabetical).
  # :all can be used as a placeholder for all plugins not explicitly named
  # config.plugins = [ :exception_notification, :ssl_requirement, :all ]

  # Skip frameworks you're not going to use. To use Rails without a database,
  # you must remove the Active Record framework.
  # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

  # Activate observers that should always be running
  # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
  config.active_record.observers = :user_observer

  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
  # Run "rake -D time" for a list of tasks for finding time zone names.
  config.time_zone = 'UTC'

  # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
  config.i18n.default_locale = :ru
end 

【问题讨论】:

    标签: ruby-on-rails rubygems captcha


    【解决方案1】:

    Gemfile 是 Rails 3 中引入的一个包装元素。在运行 Rails 2 时,您需要做一些稍微不同的事情。在你的 environment.rb 中,在 Rails::Initializer.run 块内添加这一行:

    config.gem 'rack-recaptcha', :lib => 'rack/recaptcha'
    

    【讨论】:

    • 我最初就是这样做的,但它抱怨行: /{path_to_my_project}/config/environment.rb:29 其中包含 config.middleware.use Rack::Recaptcha, :public_key => ' KEY', :private_key => 'SECRET', :paths => 'PATH' 还是不行,显示同样的错误
    • 您已经确定config.gem 行出现在您的config.middleware.use 行之前?
    • 是的,我确定。我已将列表添加到我的问题中。
    • 对不起,如果我问的问题很明显,但最好确定一下。您是否运行过rake gems:install 或确保安装了 gem?简单的测试。运行script/console。然后require 'rack/recaptcha'。然后include Rack::Recaptcha::Helpers 。发现任何错误?
    • 好像安装了:>> require 'rack/recaptcha' require 'rack/recaptcha' => [] >> include Rack::Recaptcha::Helpers include Rack::Recaptcha::Helpers => Object >> 它也出现在“gem list”中:rack-recaptcha (0.2.1)
    【解决方案2】:

    我想通了。

    我必须为 reCAPTCHA 库添加“require”语句

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多