2012-07-10 149 views
0

我一直在尝试通过Phusion Passenger使用Ruby on Rails和mySQL来设置Apache服务器。我有Apache v2.2.3,Passenger v3.0.13,Ruby v1.9.3,Rails v3.2.6和mySQL v5.0.95。Rails无法连接到mySQL

此前,由于Javascript运行时不正确,我遇到了问题,但我可以通过安装execjs和therubyracer来解决此问题。我成功地使用SQLite创建网站,但我需要使用mySQL。

现在,我用命令“rails new myProject -d mysql”创建了一个新项目,并将相应的gem添加到我的Gemfile中(也就是“gem'mysql2','0.3.11'”;“gem 'execjs'“和”gem'therubyracer'“)。

我的database.yml文件看起来像这样(的测试和生产的部分只在名称上有所不同):

development: 
    adapter: mysql2 
    encoding: utf8 
    database: myProject_development 
    pool: 5 
    username: root 
    password: 
    host: localhost 
    socket: /var/lib/mysql/mysql.sock 

现在的问题是不会立即显现。从终端,我找不到任何问题(即“耙分贝:创建”运行正常,没有出现任何错误在脚手架等),但是当我浏览网页,乘客显示以下错误:

红宝石(机架)应用程序无法启动

找不到任何的来源(捆扎机:: GemNotFound)

mysql2-0.3.11并没有网页的出现。那么,我的错在哪里?我相信我的Gemfile是正确的,我的database.yml似乎更新了,我可以从终端访问mySQL,并且我能够在SQLite中运行网站。任何建议,将不胜感激!

编辑:我的Gemfile:

source 'https://rubygems.org' 

gem 'rails', '3.2.6' 

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

gem 'mysql2','0.3.11' 


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

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

# To use Jbuilder templates for JSON 
# gem 'jbuilder' 

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

# Deploy with Capistrano 
# gem 'capistrano' 

# To use debugger 
# gem 'debugger' 

gem 'execjs' 
gem 'therubyracer' 

编辑:

Gems included by the bundle: 
    * actionmailer (3.2.6) 
    * actionpack (3.2.6) 
    * activemodel (3.2.6) 
    * activerecord (3.2.6) 
    * activeresource (3.2.6) 
    * activesupport (3.2.6) 
    * arel (3.0.2) 
    * builder (3.0.0) 
    * bundler (1.1.4) 
    * coffee-rails (3.2.2) 
    * coffee-script (2.2.0) 
    * coffee-script-source (1.3.3) 
    * erubis (2.7.0) 
    * execjs (1.4.0) 
    * hike (1.2.1) 
    * i18n (0.6.0) 
    * journey (1.0.4) 
    * jquery-rails (2.0.2) 
    * json (1.7.3) 
    * libv8 (3.3.10.4) 
    * mail (2.4.4) 
    * mime-types (1.19) 
    * multi_json (1.3.6) 
    * mysql2 (0.3.11) 
    * polyglot (0.3.3) 
    * rack (1.4.1) 
    * rack-cache (1.2) 
    * rack-ssl (1.3.2) 
    * rack-test (0.6.1) 
    * rails (3.2.6) 
    * railties (3.2.6) 
    * rake (0.9.2.2) 
    * rdoc (3.12) 
    * sass (3.1.20) 
    * sass-rails (3.2.5) 
    * sprockets (2.1.3) 
    * therubyracer (0.10.1) 
    * thor (0.15.4) 
    * tilt (1.3.3) 
    * treetop (1.4.10) 
    * tzinfo (0.3.33) 
    * uglifier (1.2.6) 

编辑:哦,我工作过的的CentOS 5.8,由 “捆名单” 的输出办法。

+1

请出示您的Gemfile。 – iblue 2012-07-10 22:35:44

+0

您是否在添加mysql2 gem后运行'bundle'? – deefour 2012-07-10 22:38:06

+0

尝试执行'bundle update' – 2012-07-10 22:52:33

回答

0

以下添加到您的Gemfile:

gem 'mysql2' 

下运行

bundle install 
+0

但我已经在我的Gemfile中有“gem'mysql2','0.3.11'”。 – 2012-07-10 23:22:29

+0

显示您的**绑定列表** – odiszapc 2012-07-11 01:28:02

+0

它包含mysql2(0.3.11)。我不知道你会找什么,但为了以防万一,我已将它添加到我的帖子中。谢谢。 – 2012-07-11 03:42:38