0

在 Windows 7 上使用 WEBrick 启动我的 rails 服务器时出现以下错误:

C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/bundler-1.3.5/lib/bundler/rubygems_integ ration.rb:214:in block in replace_gem': Please install the mysql2 adapter:gem install activerecord-mysql2-adapter`(mysql2不是一部分包。将它添加到 Gemfile。)(LoadError)

我确保 database.yml 有适配器为 mysql2,gemfile 列出了 mysql2。下面是我的 database.yml 文件和 gem 文件

    development:
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: elearn3_development
      pool: 5
      username: root
      password: password
      host: 127.0.0.1
      port: 3306

    test:
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: elearn3_test
      pool: 5
      username: root
      password: passsword
      host: 127.0.0.1
      port: 3306

    production:
      adapter: mysql2
      encoding: utf8
      reconnect: false
      database: elearn3_production
      pool: 5
      username: root
      password: passsword
      host: 127.0.0.1
      port: 3306

宝石文件:来源' https://rubygems.org '

gem 'rails', '3.2.13'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'mysql2'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

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

gem 'uglifier', '>= 1.0.3'
    end

gem 'jquery-rails'

我已经尝试了在具有相同问题的其他线程中发布的所有各种选项,例如添加 gem 'mysql2' 'version no'。它不能解决问题。我在发布 sql-lite 时也遇到了同样的问题。

感谢您的帮助。提前致谢。

编辑:当我运行捆绑安装时,我在窗口中得到以下信息。请注意 mysql2 不是使用列表的一部分。这正常吗?

    Using rake (10.0.4)
Using i18n (0.6.1)
Using multi_json (1.7.2)
Using activesupport (3.2.13)
Using builder (3.0.4)
Using activemodel (3.2.13)
Using erubis (2.7.0)
Using journey (1.0.4)
Using rack (1.4.5)
Using rack-cache (1.2)
Using rack-test (0.6.2)
Using hike (1.2.2)
Using tilt (1.4.0)
Using sprockets (2.2.2)
Using actionpack (3.2.13)
Using mime-types (1.23)
Using polyglot (0.3.3)
Using treetop (1.4.12)
Using mail (2.5.3)
Using actionmailer (3.2.13)
Using arel (3.0.2)
Using tzinfo (0.3.37)
Using activerecord (3.2.13)
Using activeresource (3.2.13)
Using coffee-script-source (1.6.2)
Using execjs (1.4.0)
Using coffee-script (2.2.0)
Using rack-ssl (1.3.3)
Using json (1.7.7)
Using rdoc (3.12.2)
Using thor (0.18.1)
Using railties (3.2.13)
Using coffee-rails (3.2.2)
Using jquery-rails (2.2.1)
Using bundler (1.3.5)
Using rails (3.2.13)
Using sass (3.2.8)
Using sass-rails (3.2.6)
Using uglifier (2.0.1)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

编辑在尝试了http://www.mohanarun.com/how-to-install-mysql-adapter-ruby-gem-in-windows/的说明后,我看到捆绑安装正在获取 mysql。但是,当我做 Rails 服务器时,我得到了以下错误。

/* 之前还有很多错误 */

pport/core_ext/load_error.rb 369 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/core_ext/name_error.rb 370 C:/Ruby200-x64 /lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/core_ext/uri.rb 371 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionpack -3.2.13/lib/action_contr oller.rb 372 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_view/railtie.rb 373 C:/Ruby200- x64/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/abstract_controller/railties/routes_helpers.rb 374 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/ actionpack-3.2.13/lib/action_controller/railties/paths.rb 375 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/action_controller/railtie.rb 376 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activerecord-3.2.13/lib/active_rec ord/railtie.rb 377 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionmailer-3.2.13/lib/action_mailer/version.rb 378 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems /activesupport-3.2.13/lib/active_su pport/core_ext/class/delegating_attributes.rb 379 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/ core_ext/module/reachable.rb 380 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/core_ext/class/subclasses.rb 381 C:/Ruby200 -x64/lib/ruby/gems/2.0.0/gems/activesupport-3.2.13/lib/active_su pport/core_ext/class.rb 382 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems /activesupport-3.2.13/lib/active_su pport/core_ext/array/uniq_by.rb 383 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionmailer-3.2.13/lib/action_mailer。 rb 384 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionmailer-3.2.13/lib/action_mailer/railtie.rb 385 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activeresource-3.2.13/lib/active_resource/exceptions.rb 386 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems /activeresource-3.2.13/lib/active_resource/version.rb 387 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/activeresource-3.2.13/lib/active_resource.rb 388 C: /Ruby200-x64/lib/ruby/gems/2.0.0/gems/activeresource-3.2.13/lib/active_resource/railtie.rb 389 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems /railties-3.2.13/lib/rails/test_unit/railtie.rb 390 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/actionpack-3.2.13/lib/sprockets/ra iltie。 rb 391 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/railties-3.2.13/lib/rails/all.rb 392 C:/Ruby200-x64/lib/ruby/gems/2.0。 0/gems/activesupport-3.2.13/lib/active_su pport/string_inquirer.rb 393 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/lib/mysql2/version。 RB 394 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/mysql2-0.3.11/lib/mysql2/error.rb 395 C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/ mysql2-0.3.11/lib/mysql2/result.rb

[注意] 您可能在 Ruby 解释器或扩展库中遇到了错误。欢迎提交错误报告。详情:错误报告

此应用程序已请求运行时以不寻常的方式终止它。请联系应用程序的支持团队以获取更多信息。

4

3 回答 3

3

确保将以下内容添加到您的 Gemfile:

gem 'mysql'
gem 'mysql2', "~> 0.3.10"

然后运行

bundle install

问题太老了,但这可能对其他人有帮助。

于 2015-11-16T08:09:40.630 回答
0

生产中发生了同样的问题,以下是问题。

  1. 必须将 sqlite gem 移至 Gemfile 中的开发
  2. 必须将 mysql2 gem 添加到 Gemfile 中的部署
  3. 必须运行 bundle install 来更新 Gemlock
  4. 必须将这些更改提交给 git 并更新远程 git repo。

这些步骤非常适合我的生产设置,但我希望它们对其他人也有帮助。

于 2013-08-03T05:10:27.110 回答
0

修改 Gemfile 和 bundle install 后,你应该重启 Rails 服务器,它可以重新加载 bundle gem

于 2013-07-31T04:17:31.837 回答