rails g gives uninitialized constant Rack::Mongoid
I get this error when I run 'rails g' (my app seems to run fine otherwise though, but I need to use a generator):
/home/love/mongodb.roger/.bundler/ruby/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/methods.rb:113:in `constantize': uninitialized constant Rack::Mongoid (NameError)
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/methods.rb:112:in `each'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/activesupport-3.0.9/lib/active_support/inflector/methods.rb:112:in `constantize'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:14:in `klass'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:33:in `build'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:79:in `build'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/application.rb:209:in `inject'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:79:in `each'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:79:in `inject'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/actionpack-3.0.9/lib/action_dispatch/middleware/stack.rb:79:in `build'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/application.rb:162:in `build_middleware_stack'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/application/finisher.rb:35
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `instance_exec'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:25:in `run'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:50:in `run_initializers'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `each'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/initializable.rb:49:in `run_initializers'
from /home开发者_JAVA技巧/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/application.rb:134:in `initialize!'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `send'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/application.rb:77:in `method_missing'
from /home/love/mongodb.roger/config/environment.rb:7
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/application.rb:103:in `require_environment!'
from /home/love/mongodb.roger/.bundler/ruby/1.8/gems/railties-3.0.9/lib/rails/commands.rb:16
from script/rails:6:in `require'
from script/rails:6
I use 1.8.7 (but I also get this error when I use 1.9.x with RVM).
ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
rails -v
Rails 3.0.9
cat Gemfile
source 'http://rubygems.org'
gem 'rails', '3.0.9'
gem "mongoid", "~> 2.1.0"
gem "bson_ext", "~> 1.3"
gem "devise" #, :git=>"https://github.com/plataformatec/devise.git"
gem "rails-footnotes", ">= 3.7", :group => :development
gem "compass"
gem 'SystemTimer'
gem "oa-oauth", :require => "omniauth/oauth"
gem "warden"
gem 'formtastic', '~> 1.1.0'
gem 'paperclip'
gem 'jquery-rails'
gem 'acts-as-taggable-on'
gem "gmaps4rails"
gem 'browser'
gem 'apotomo', "~>1.1.0"
gem 'sass'
gem 'chunky_png'
gem 'mongoid-paperclip'
Does anyone have any idea ?
remove the line from your config/application.rb
file:
require "mongoid/railtie"
I have seen this issue on migrating from Rails 3.0.7 to Rails 3.1.3 when using Mongoid. To fix the problem find you where are doing all your mongoid requires - for example - in config/application.rb
require 'mongoid/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'active_resource/railtie'
require 'rails/test_unit/railtie'
... then add require 'rack/mongoid' just before this to give you...
require 'rack/mongoid' # TADA!
require 'mongoid/railtie'
require 'action_controller/railtie'
require 'action_mailer/railtie'
require 'active_resource/railtie'
require 'rails/test_unit/railtie'
This got the Rails console working for me as well (rails c)
精彩评论