请安装先后顺序安装
第一:安装ruby
安装包下载地址:http://rubyforge.org/frs/?group_id=167 ,可以下载1.8.6-26 和 ruby-1.8.7。
先安装完1.8.6-26,然后将ruby-1.8.7解压并覆盖到1.8.6-26安装目录,这样就可以完成ruby-1.8.7的安装。
可以用ruby -v 测试是否安装成功,同时还可以查看版本,如图, 就说明安装成功了
<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->
第二:安装rails, 但是前提条件是一下文件存在,可以通过在cmd下运行gem install -l *.gem(全路径)来进行安装
下载路径:
http://rubyforge.org/
需要的前提文件:
actionmailer-2.2.3.gem
actionpack-2.2.3.gem
activerecord-2.2.3.gem
activeresource-2.2.3.gem
activesupport-2.2.3.gem
rails文件:
rails-2.2.3.gem
PS: 可以把这些文件放在一起,只安装rails文件,系统会自动查找其他文件
第三:安装MySQL驱动
下载路径:
http://rubyforge.org/
mysql-2.8.1-x86-mswin32.gem
1) 将ruby路径下的:ruby/lib/ruby/gems/1.8/gems/mysql-2.8.1-x86-mingw32/lib/1.8下的mysql.so(或者mysql_api.so)拷贝到ruby下的:ruby/lib/ruby/site_ruby/1.8/i386-msvcrt下
2) 将Mysql安装目录下的bin目录下的libmysql.dll拷到比如ruby下的ruby/bin下
第四: 创建Web应用
在cmd下输入rails d://test, 即可生成工程test, 然后进入script目录下输入:ruby server来启动服务
最后在浏览器中输入http://localhost:3000, 即可登陆系统页面
第五: 编写测试脚本
d:/test.rb:
require "mysql"
dbc=Mysql.real_connect('127.0.0.1','root','mysql','testmysql')
res=dbc.query('select * from person')
while row=res.fetch_row do
puts "#{row[0]}"
end
运行: ruby d:/test.rb
查看运行结果
<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} -->