无法使mongo在Windows上使用rails

时间:2013-07-08 08:57:52

标签: ruby-on-rails windows mongodb mongoid

我正在尝试用rails测试mongoDB,我对这两者都很新。

首先,mongoDB已安装并作为Windows服务运行。

现在,这是我创建一个简单应用程序的步骤:

我用这个创建了应用程序:

rails new MongoOnRailsBlog -O -J -T

然后我修改了gemfile,它现在看起来像这样:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'

gem 'mongoid'
gem 'bson_ext'
gem 'will_paginate'
gem 'devise'
gem 'haml'
gem 'haml-rails', :group => :development
gem 'hpricot', :group => :development
gem 'formtastic'
gem 'jquery-rails'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

我修改了application.rb以添加一些生成器:

require File.expand_path('../boot', __FILE__)

require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module MongoOnRailsBlog
  class Application < Rails::Application

    # Configure generators  
    config.generators do |g|  
      g.orm :mongoid  
      g.template_engine :haml  
    end  
  end
end

然后当我尝试生成mongoID配置时,使用:

rails generate mongoid:config

我有“无法加载文件错误”

C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require': cannot load such file -- mongoid/version (LoadError)
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/devise-1.5.4/lib/devise/rails.rb:34:in `block in <class:Engine>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
    from C:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
    from C:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) ineach_strongly_connected_component'
    from C:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
    from C:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
    from C:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:180:in `each'
    from C:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
    from C:/Ruby200-x64/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from E:/Dev/Projects/MongoOnRailsBlog/config/environment.rb:5:in `<top (required)>'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:189:in `require_environment!'
    from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:45:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

我猜它与MongoID的好版本有关,但我不知道在哪里验证,如何确保它加载好的...

有关何处查看的任何建议?

感谢。

2 个答案:

答案 0 :(得分:0)

对于将来的问题,请提供Rails和Mongoid的确切版本信息。如果你看一下Gemfile.lock,很可能是捆绑器在mongoid 3.1.4中引入了。如果你查看Github并比较标记v3.1.4与分支主文件的提交,很明显Rails 4支持不包含在v3.1.4中。 Mongoid for Rails 4的正式发布仍在等待中。

所以在这一刻,我建议您重新使用Rails 3(目前为3.2.13)取得圆满成功。

答案 1 :(得分:0)

现在,放入你的Gemfile:

gem 'mongoid', github: 'mongoid/mongoid'