开发新的webapp Rails MongoDB

时间:2016-07-08 03:58:39

标签: ruby-on-rails ruby mongodb web-applications

我一直在为activemodel遇到不兼容问题。当前错误是;

Bundler could not find compatible versions for gem "activemodel":
  In Gemfile:
    mongoid (~> 4.0.0) was resolved to 4.0.0, which depends on
      activemodel (~> 4.0)

    rails (~> 5.0.0) was resolved to 5.0.0, which depends on
      activemodel (= 5.0.0)

    rails (~> 5.0.0) was resolved to 5.0.0, which depends on
      activemodel (= 5.0.0)

我当前的版本是;

  • Rails 5.0.0
  • ruby​​ 2.2.2p95
  • Mongo版本:3.2.6

在另一个但类似的行上,我设置我的webapp没有活动记录,并且还卸载了gem但它似乎总是在我的gemfile中重新出现。

创建我的webapp时 -

rails new test-app --skip-active-record --skip-test-unit

的Gemfile:

source 'https://rubygems.org'
gem 'rails', '~> 5.0.0'

group :assets do
        # Use SCSS for stylesheets
        gem 'sass-rails', '~> 5.0'
        # Use Uglifier as compressor for JavaScript assets
        gem 'uglifier'
        # Use CoffeeScript for .coffee assets and views
        gem 'coffee-rails'
end
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Mongo linker
gem 'mongoid', git: 'https://github.com/estolfo/mongoid.git'
# Turbolinks makes navigating web application faster.
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder'
group :development do
  gem 'better_errors'
  gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
  gem 'quiet_assets'
end
#Rspec for unit testing
gem "rspec-rails", :group => [:development, :test]
gem 'figaro'
gem "capybara", :group => :test
gem "database_cleaner", :group => :test
gem "mongoid-rspec", :group => :test
gem "email_spec", :group => :test
gem "cucumber-rails", :group => :test, :require => false
gem "launchy", :group => :test
gem "factory_girl_rails", :group => [:development, :test]
gem "devise"
gem 'therubyracer', platforms: :ruby

一旦我改变我的Gemfile特别是mongoid

gem 'mongoid', git: 'https://github.com/estolfo/mongoid.git', branch: 'MONGOID-4218-rails-5'

错误来了 -

Bundler could not find compatible versions for gem "activesupport":
  In Gemfile:
    mongoid was resolved to 6.0.0, which depends on
      activemodel (= 5.0.0.beta3) was resolved to 5.0.0.beta3, which depends on
        activesupport (= 5.0.0.beta3)

    rails (~> 5.0.0) was resolved to 5.0.0, which depends on
      activesupport (= 5.0.0)

    rails (~> 5.0.0) was resolved to 5.0.0, which depends on
      activesupport (= 5.0.0)

    rails (~> 5.0.0) was resolved to 5.0.0, which depends on
      activesupport (= 5.0.0)

2 个答案:

答案 0 :(得分:1)

我能够使用您在问题中提供的步骤以及Gemfile重新创建您的开发环境。在我的情况下,我已设法解决您提到的冲突并安装mongoid gem,如下所示。

首先,我不知道你为什么使用official mongoid repository的分叉回购。这样,我决定使用官方gem并更改了Gemfile中的行(虽然我认为这个解决方案仍然有效,以防你想从其他仓库安装gem):gem 'mongoid'。< / p>

之后,我执行了bundle install并收到以下错误:

Bundler could not find compatible versions for gem "railties":
  In Gemfile:
    quiet_assets (>= 1.0.2) was resolved to 1.0.2, which depends on
      railties (< 5.0, >= 3.1)

    rails (~> 5.0.0) was resolved to 5.0.0, which depends on
      railties (= 5.0.0)

    rspec-rails was resolved to 3.5.1, which depends on
      railties (>= 3.0)

    sass-rails (~> 5.0) was resolved to 5.0.5, which depends on
      railties (< 6, >= 4.0.0)

检查输出我发现冲突的宝石是quiet_assets。考虑到这一点,我访问了quiet_assets GitHub repository并在其README.md中找到了以下内容:

  

弃用

     

从sprockets-rails版本3.1.0开始,在当前版本中使用   rails,这个gem已被弃用。

     

资产管道现在支持一个禁止输出的安静选项   资产申请:

# config/environments/development.rb

config.assets.quiet = true
     

相关公关:https://github.com/rails/sprockets-rails/pull/355

现在可以完成此gem的功能,将这一小部分配置添加到您的Rails环境文件中,因此我从quiet_assets删除了需要Gemfile的行,将文档保留为如下:

source 'https://rubygems.org'
gem 'rails', '~> 5.0.0'

group :assets do
        # Use SCSS for stylesheets
        gem 'sass-rails', '~> 5.0'
        # Use Uglifier as compressor for JavaScript assets
        gem 'uglifier'
        # Use CoffeeScript for .coffee assets and views
        gem 'coffee-rails'
end
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Mongo linker
gem 'mongoid'
# Turbolinks makes navigating web application faster.
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder'
group :development do
  gem 'better_errors'
  gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
end
#Rspec for unit testing
gem "rspec-rails", :group => [:development, :test]
gem 'figaro'
gem "capybara", :group => :test
gem "database_cleaner", :group => :test
gem "mongoid-rspec", :group => :test
gem "email_spec", :group => :test
gem "cucumber-rails", :group => :test, :require => false
gem "launchy", :group => :test
gem "factory_girl_rails", :group => [:development, :test]
gem "devise"
gem 'therubyracer', platforms: :ruby

执行另一个bundle install后,这次成功安装了所有依赖项。

我希望这可以帮到你。如果此解决方案不符合您的需求,请告诉我。

答案 1 :(得分:0)

使用gem uninstall rails卸载Rails。

您目前拥有Rails 5.0.0,但需要来自5.0.0.beta3的activesupport。

因此,您应该运行gem install rails -v 5.0.0.beta3

然后尝试rails new