这是 windows users 的解决方案,希望有所帮助!
在Windows上使用MySQL和Rails 3
Install railsinstaller - > www.railsinstaller.org(我将它安装到c:\ Rails)
Install MySQL (我使用MySQL 5.5) - > dev.mysql.com/downloads/installer/
---用于mySQL安装---如果你还没有安装这两个文件,你可能需要它们才能让你的MySQL运行vcredist_x86.exe - > http://www.microsoft.com/download/en/details.aspx ?id = 5555 dotNetFx40_Full_x86_x64.exe - > http://www.microsoft.com/download/en/details.aspx?id=17718使用默认安装Developer Machine -MySQL Server配置:3306 windows服务名称:MySQL55 mysql root pass:root(你可以稍后更改)(用户名:root)-MySQL Server Config- ---用于mySQL安装---
---安装mysql2 Gem ---重要:用Git Bash命令行(这是用railsinstaller安装) - > start / Git Bash gem install mysql2 - ' - with-mysql-lib =“c: \ Program Files \ MySQL \ MySQL Server 5.5 \ lib“--with-mysql -include =”c:\ Program Files \ MySQL \ MySQL Server 5.5 \ include“'现在gem应该已经正确安装最后复制libmysql.dll文件从C:\ Program Files \ MySQL \ MySQL Server 5.5 \ lib到C:\ Rails \ Ruby1.9.2 \ bin ---安装mysql2 Gem ---
如果您不确定如何使用MySQL读取创建Rails 3应用程序,您现在可以将您的Rails应用程序与MySQL一起使用...
--- Get a Rails 3 app going with MySQL ---
打开命令提示符(不是Git Bash) - > start / cmd
导航到您的文件夹(c:\ Sites)
创建新的rails应用程序
rails new world
删除文件c:\ Sites \ world \ public \ index.html
编辑文件c:\ Sites \ world \ config \ routes.rb
添加这一行 - > root:to => 'cities#index'
打开命令提示符(生成视图和控制器)
rails generate scaffold city ID:integer Name:string CountryCode:string District:string Population:integer
编辑文件c:\ Sites \ world \ app \ models \ city.rb,如下所示
class City < ActiveRecord::Base
set_table_name "city"
end
编辑文件c:\ Sites \ world \ config \ database.yml看起来像这样
development:
adapter: mysql2
encoding: utf8
database: world
pool: 5
username: root
password: root
socket: /tmp/mysql.sock
添加到gemfile
gem 'mysql2'
打开 command prompt windows cmd,而不是Git Bash(运行你的应用!)
导航到您的应用程序文件夹(c:\ Sites \ world)
rails s
--- Get a Rails 3 app going with MySQL ---