Rails 4:一起使用MySql和MongoDB [英] Rails 4: Use MySql and MongoDB together

查看:157
本文介绍了Rails 4:一起使用MySql和MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MongoDB(mongoid)和MySQL一起在Rails 4中创建一个应用程序. 但是我无法设置它.

I'm trying to make an application in rails 4 using MongoDB(mongoid) and MySQL together. But I'm not able to set it up.

我正在执行以下步骤:

  1. rails new myapp -d mysql
  2. 然后将这些行添加到Gemfile中:
    gem "mongoid"
    gem "bson_ext"
  3. bundle install
  4. rails g mongoid:config
  1. rails new myapp -d mysql
  2. Then added these lines to Gemfile:
    gem "mongoid"
    gem "bson_ext"
  3. bundle install
  4. rails g mongoid:config

步骤4失败.我无法解决问题.它显示以下错误.

The step 4 fails. I'm not able to figure out the problem. It shows the following error.

/home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations.rb:5:in require': /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations/has_many.rb:79: syntax error, unexpected keyword_do_cond, expecting ':' @documents = attributes ? attributes.collect do |attrs| ^ /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations/has_many.rb:84: syntax error, unexpected ':', expecting keyword_end end : [] ^ /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations/has_many.rb:99: syntax error, unexpected keyword_do_cond, expecting keyword_end attributes.values.each do |attrs| ^ /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations/has_many.rb:139: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError) from /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations.rb:5:in' 来自/home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid.rb:40:in require' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid.rb:40:in' 来自/home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:在require' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in块中(2个级别)中require' 来自/home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in each' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in block in require' 来自/home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:在each' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in中需要' 来自/home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler.rb:134:in require' from /home/devesh/fashion_hub/store/config/application.rb:7:in' 来自/home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:82:in require' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:82:in preload' 来自/home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:143:in serve' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:131:in block in run' 从/home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:125:在loop' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:125:in run' 从/home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application/boot.rb:18:在<top (required)>' from /home/devesh/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in中要求' 来自/home/devesh/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:在'require'中

/home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations.rb:5:in require': /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations/has_many.rb:79: syntax error, unexpected keyword_do_cond, expecting ':' @documents = attributes ? attributes.collect do |attrs| ^ /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations/has_many.rb:84: syntax error, unexpected ':', expecting keyword_end end : [] ^ /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations/has_many.rb:99: syntax error, unexpected keyword_do_cond, expecting keyword_end attributes.values.each do |attrs| ^ /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations/has_many.rb:139: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError) from /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations.rb:5:in' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid.rb:40:in require' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid.rb:40:in' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in require' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:inblock (2 levels) in require' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in each' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:inblock in require' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in each' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:inrequire' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler.rb:134:in require' from /home/devesh/fashion_hub/store/config/application.rb:7:in' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:82:in require' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:82:inpreload' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:143:in serve' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:131:inblock in run' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:125:in loop' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:125:inrun' from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application/boot.rb:18:in <top (required)>' from /home/devesh/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /home/devesh/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'

我正在关注一些细节:

  1. 操作系统-ubuntu 14.04
  2. 红宝石v2.2.2
  3. 导轨4.2.3

推荐答案

将以下行添加到您的application.rb文件中:
config.generators do |g| g.orm :active_record end

add these line to your application.rb file:
config.generators do |g| g.orm :active_record end

这将迫使rails g使用活动记录.

This will force rails g to use active record.

每当要为mongodb生成模型时,请使用:
rails g mongoid:model yourmodelname

And whenever you want to generate a model for mongodb, use:
rails g mongoid:model yourmodelname

这篇关于Rails 4:一起使用MySql和MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆