views:

37

answers:

2

I have followed steps, described in rack-recaptcha readme.

I have done all the steps, instead of "You have to require 'rack-recaptcha' in your gemfile."

Server is unable to start, because of a following error:

 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

I think, the step with "gemfile", that i'm skipped, is the reason of this error.

But, i don't know, where should i look for the mentioned "gemfile" ?

Help, please


Update:

environment.rb is following

# 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  A: 

The Gemfile is a packaging element introduced in Rails 3. As you're running Rails 2 you need to do something slightly different. In you environment.rb add this line inside the Rails::Initializer.run block:

config.gem 'rack-recaptcha', :lib => 'rack/recaptcha'
bjg
I have initially done exactly this, but it complains to line:/{path_to_my_project}/config/environment.rb:29which containsconfig.middleware.use Rack::Recaptcha, :public_key => 'KEY', :private_key => 'SECRET', :paths => 'PATH'It still not working, displaying the same errors
AntonAL
And you've made sure that the `config.gem` line appears **before** your `config.middleware.use` line?
bjg
Yes, i'm sure. I have added the listing to my question.
AntonAL
Sorry if I'm asking obvious questions but it's best to be sure. Have you run `rake gems:install` or made sure that gem is installed? Simple test. Run `script/console`. Then `require 'rack/recaptcha'`. Then `include Rack::Recaptcha::Helpers`. See any errors?
bjg
It seems to be installed: >> require 'rack/recaptcha' require 'rack/recaptcha' => [] >> include Rack::Recaptcha::Helpers include Rack::Recaptcha::Helpers => Object >>It is also presented in "gem list": rack-recaptcha (0.2.1)
AntonAL
bjg
A: 

I've figured it out.

I must add "require" statement for reCAPTCHA library

AntonAL