无法使用“rack-recaptcha”gem启动服务器

时间:2010-07-21 10:28:25

标签: ruby-on-rails rubygems captcha

我遵循了rack-recaptcha readme中描述的步骤。

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

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

 Booting Mongrel
 => Rails 2.3.5 application starting on 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:in `load'
    -e:2
 Uncaught exception: uninitialized constant 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 

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

我已经明白了。

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