5

这可能是一个新手设置问题。但是这里...

机器设置

我有一台运行 rails 4.0.0 和 ruby​​ 2.0.0 的 Windows 7 64 位机器我的路径中有以下内容

C:\Ruby200-x64\bin;C:\RubyDevKit\bin;C:\RubyDevKit\mingw\bin;

项目设置

我正在从同事的工作存储库中克隆一个 git 项目。

当我运行我的初始

rake db:migrate

我收到以下错误

rake aborted!
Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 's
qlite3'` to your Gemfile.
C:/Working/mynewproject/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

我的 Gemfile 确实包含 gem 'sqlite3' 如下

# Use sqlite3 as the database for Active Record
gem 'sqlite3' 

完整的 Gemfile 是

source 'https://rubygems.org'

ruby '2.0.0'

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

# Use sqlite3 as the database for Active Record
gem 'sqlite3' 

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

# Use Twitter Bootstrap for styling
gem 'bootstrap-sass'

# 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'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

# 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

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]

gem 'protected_attributes' # should probably use strong parameters!

当我运行时,bundle install我得到以下列表 - 请注意缺少 sqlite3

Using rake (10.1.0)
Using i18n (0.6.5)
Using minitest (4.7.5)
Using multi_json (1.7.9)
Using atomic (1.1.13)
Using thread_safe (0.1.2)
Using tzinfo (0.3.37)
Using activesupport (4.0.0)
Using builder (3.1.4)
Using erubis (2.7.0)
Using rack (1.5.2)
Using rack-test (0.6.2)
Using actionpack (4.0.0)
Using mime-types (1.25)
Using polyglot (0.3.3)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (4.0.0)
Using activemodel (4.0.0)
Using activerecord-deprecated_finders (1.0.3)
Using arel (4.0.0)
Using activerecord (4.0.0)
Using sass (3.2.10)
Using bootstrap-sass (2.3.2.2)
Using coffee-script-source (1.6.3)
Using execjs (2.0.1)
Using coffee-script (2.2.0)
Using thor (0.18.1)
Using railties (4.0.0)
Using coffee-rails (4.0.0)
Using hike (1.2.3)
Using jbuilder (1.5.1)
Using jquery-rails (3.0.4)
Using json (1.8.0)
Using protected_attributes (1.0.3)
Using bundler (1.3.5)
Using tilt (1.4.1)
Using sprockets (2.10.0)
Using sprockets-rails (2.0.0)
Using rails (4.0.0)
Using rails_serve_static_assets (0.0.1)
Using rails_stdout_logging (0.0.2)
Using rails_12factor (0.0.2)
Using rdoc (3.12.2)
Using sass-rails (4.0.0)
Using sdoc (0.3.20)
Using turbolinks (1.3.0)
Using uglifier (2.2.1)
Your bundle is complete!

当我这样做时,bundle show 'sqlite3'我得到

Could not find gem 'sqlite3'.
Did you mean sqlite3?

当我这样做时,gem install 'sqlite3'我得到

Successfully installed sqlite3-1.3.8-x64-mingw32
Parsing documentation for sqlite3-1.3.8-x64-mingw32
unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/sqlite3/2.0/sqlite3_native.so, skipping
1 gem installed

在搜索到有关“无法转换”的错误后,我发现我可以在没有文档的情况下安装。所以,如果我这样做

gem install 'sqlite3' --no-doc 

我明白了

Successfully installed sqlite3-1.3.8-x64-mingw32
1 gem installed

然后当我这样做时

rake db:migrate

我仍然得到

rake aborted!
Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 's
qlite3'` to your Gemfile.
C:/Working/mynewproject/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

那么,我错过了什么?

谢谢

做完评论中建议的事情后更新:

由于Doon的评论,我已将 gemfile 内容放在上述问题的描述中

为了回应techvineet的评论,我跑bundle install了好几次,输出一致。

由于zrl3dx的评论,我现在已经运行bundle exec bundle并获得相同的输出,即

Using rake (10.1.0)
Using i18n (0.6.5)
Using minitest (4.7.5)
Using multi_json (1.7.9)
Using atomic (1.1.13)
Using thread_safe (0.1.2)
Using tzinfo (0.3.37)
Using activesupport (4.0.0)
Using builder (3.1.4)
Using erubis (2.7.0)
Using rack (1.5.2)
Using rack-test (0.6.2)
Using actionpack (4.0.0)
Using mime-types (1.25)
Using polyglot (0.3.3)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (4.0.0)
Using activemodel (4.0.0)
Using activerecord-deprecated_finders (1.0.3)
Using arel (4.0.0)
Using activerecord (4.0.0)
Using sass (3.2.10)
Using bootstrap-sass (2.3.2.2)
Using coffee-script-source (1.6.3)
Using execjs (2.0.1)
Using coffee-script (2.2.0)
Using thor (0.18.1)
Using railties (4.0.0)
Using coffee-rails (4.0.0)
Using hike (1.2.3)
Using jbuilder (1.5.1)
Using jquery-rails (3.0.4)
Using json (1.8.0)
Using protected_attributes (1.0.3)
Using bundler (1.3.5)
Using tilt (1.4.1)
Using sprockets (2.10.0)
Using sprockets-rails (2.0.0)
Using rails (4.0.0)
Using rails_serve_static_assets (0.0.1)
Using rails_stdout_logging (0.0.2)
Using rails_12factor (0.0.2)
Using rdoc (3.12.2)
Using sass-rails (4.0.0)
Using sdoc (0.3.20)
Using turbolinks (1.3.0)
Using uglifier (2.2.1)
Your bundle is complete!

由于Sachin Singh的评论,我删除了 Gemfile.lock 并运行bundle install。结果几乎相同:

Fetching gem metadata from https://rubygems.org/..........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.1.0)
Using i18n (0.6.5)
Using minitest (4.7.5)
Using multi_json (1.7.9)
Using atomic (1.1.13)
Using thread_safe (0.1.2)
Using tzinfo (0.3.37)
Using activesupport (4.0.0)
Using builder (3.1.4)
Using erubis (2.7.0)
Using rack (1.5.2)
Using rack-test (0.6.2)
Using actionpack (4.0.0)
Using mime-types (1.25)
Using polyglot (0.3.3)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (4.0.0)
Using activemodel (4.0.0)
Using activerecord-deprecated_finders (1.0.3)
Using arel (4.0.0)
Using activerecord (4.0.0)
Using sass (3.2.10)
Using bootstrap-sass (2.3.2.2)
Using bundler (1.3.5)
Using coffee-script-source (1.6.3)
Using execjs (2.0.1)
Using coffee-script (2.2.0)
Using thor (0.18.1)
Using railties (4.0.0)
Using coffee-rails (4.0.0)
Using hike (1.2.3)
Using jbuilder (1.5.1)
Using jquery-rails (3.0.4)
Using json (1.8.0)
Using protected_attributes (1.0.3)
Using tilt (1.4.1)
Using sprockets (2.10.0)
Using sprockets-rails (2.0.0)
Using rails (4.0.0)
Using rails_serve_static_assets (0.0.1)
Using rails_stdout_logging (0.0.2)
Using rails_12factor (0.0.2)
Using rdoc (3.12.2)
Using sass-rails (4.0.0)
Using sdoc (0.3.20)
Using turbolinks (1.3.0)
Using uglifier (2.2.1)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

所以仍然没有提到 sqlite3 并且rake db:migrate仍然导致

rake aborted!
Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 's
qlite3'` to your Gemfile.
C:/Working/its-a-disaster/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)

在回答Sachin Singh的问题时,输出是ruby -v command什么?

它说:

ruby 2.0.0p247 (2013-06-27) [x64-mingw32]

和 rails --version 说

Rails 4.0.0

Prusswan asked are there other ruby installations on the same machine?

There were three - 1.9.2, 1.9.3 and 2.0.0 The latter is the one in the path. The other two I have since removed.

4

1 回答 1

8

There is a known problem with Bundler and 64bits Ruby, which is not detecting x64-mingw32 gem platforms into the bundle, thus making it fail.

I believe this has been fixed in the 1.4.0 pre-release versions, and you can try that by doing:

gem update bundler --pre

bundle install

There are other issues you might encounter with the 64bits version. The following is my personal recommendation about it:

Unless you're really forced to work or create applications that uses more than 2GB of RAM (most likely not a Rails application), I recommend you use the 32bits version of Ruby (and the respective DevKit)

While you have a 64bits version of Windows, the system is quite capable of running 32bits applications without issues. There is no performance degradation that can be noticeable when developing Web applications with Rails.

While Ruby 2.0.0 has been marked as stable and production ready, not all the gems and related tools has been updated to work properly with it. There are still some rough edges that needs to be ironed out, as you can see on the case of Bundler and 64bits Ruby. As most of the open-source software, this is a community effort and help might be required.

Hope this helps.

于 2013-09-04T13:46:12.033 回答