我正在尝试结合使用 MongoDB(mongoid) 和 MySQL 在 Rails 4 中创建一个应用程序。
但我无法设置它。
我正在按照以下步骤操作:
rails new myapp -d mysql
- 然后将这些行添加到 Gemfile 中:
gem "mongoid"
gem "bson_ext"
bundle install
rails g mongoid:config
步骤 4 失败。我无法找出问题所在。它显示以下错误。
/home/devesh/.rvm/gems/ruby-2.2.2/gems/mongoid-1.0.6/lib/mongoid/associations.rb:5:inrequire': /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:inrequire'
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:inrequire'
from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in
require' 中的块(2 级)
来自/home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:ineach'
from /home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in
阻止 require'
来自/home/devesh/.rvm/gems/ruby-2.2.2/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:ineach'
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:inrequire'
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:inrequire'
from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:82:in
预载'
来自/home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:143:inserve'
from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:131:in
阻止运行'
来自/home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:125:inloop'
from /home/devesh/.rvm/gems/ruby-2.2.2/gems/spring-1.3.6/lib/spring/application.rb:125:in
跑步'
来自/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:in
要求'
来自 /home/devesh/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
我正在关注这个url https://sachkadam.wordpress.com/2013/05/03/setup-a-rails-app-to-use-both-mongodb-and-mysql-together/.
一些细节:
- 操作系统-ubuntu 14.04
- 红宝石 v2.2.2
- 导轨 4.2.3
将这些行添加到您的application.rb
file:
config.generators do |g|
g.orm :active_record
end
这将强制 Rails g 使用活动记录。
每当您想为 mongodb 生成模型时,请使用:
rails g mongoid:model yourmodelname
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)