【www.gdgbn.com--ruby】

1) 安装ruby

       下载安装包:http://rubyforge.org/frs/?group_id=167,我下载的是rubyinstaller-1.8.7-p302.exe

装完后,可以用ruby -v 测试是否安装成功,如图,要是出现了版本 就说明安装成功了

image

2)安装rubygems

      rubygems是ruby的包管理器工具,它使得ruby包的安装十分简单,只需要一条命令就可以从远程服务器上下载相应的包,如果相应的应用包含其他扩展,rubygems 也会提示你从远程安装所依赖的扩展。安装后 rubygems 会运行相应的程序生成 rdoc 帮助文档(类似于 javadoc )。目前已经成为 ruby 事实上的包管理器标准了。

下载地址:http://rubyforge.org/projects/rubygems/

我下载的是rubygems-1.3.7,解压后执行目录下的setup.rb,安装完成以后,用如下命令检查:

gem –v

image

3、安装rails

      a)远程安装:gem install rails –remote

       下面来自于网上的说明我没有采用这种方式安装,因为我家 的网速太慢了。

然后会自动输出: 
install required dependency activerecord?
install required dependency actionpack?
install required dependency actionmailer?
install required dependency activeresource?
依次yes依赖文件,然后显示:
successfully installed rails-2.1.0
successfully installed activerecord-2.1.0
successfully installed actionpack-2.1.0
successfully installed actionmailer-2.1.0
successfully installed activeresource-2.1.0
installing ri documentation for activerecord-2.1.0...
installing ri documentation for actionpack-2.1.0...
installing ri documentation for actionmailer-2.1.0...
installing ri documentation for activeresource-2.1.0...
installing rdoc documentation for activerecord-2.1.0...
installing rdoc documentation for actionpack-2.1.0...
installing rdoc documentation for actionmailer-2.1.0...
installing rdoc documentation for activeresource-2.1.0...
看看版本:rails -v
输出:rails 2.1.0
搞定

        b)本地手动安装:

   需要下载

    activesupport

http://files.rubyforge.vm.bytemark.co.uk/activesupport/activesupport-2.2.3.gem

            activerecord

http://files.rubyforge.vm.bytemark.co.uk/activerecord/activerecord-2.2.3.gem

            actionpack

http://files.rubyforge.vm.bytemark.co.uk/actionpack/actionpack-2.2.3.gem

     actionmailer

php教程/64424/actionmailer-2.2.3.gem" href="http://rubyforge.org/frs/download.php/64424/actionmailer-2.2.3.gem">http://rubyforge.org/frs/download.php/64424/actionmailer-2.2.3.gem

    rake
http://files.rubyforge.vm.bytemark.co.uk/rake/rake-0.8.7.gem

   activeresource

  http://rubyforge.org/frs/download.php/64419/activeresource-2.2.3.gem

    rails     http://rubyforge.org/frs/download.php/64426/rails-2.2.3.gem

下载完成之后将所有文件放在同一个文件夹下面依次安装:(eg:d:ruby)

    然后执行命令

   (d: --> d:>cd d:ruby)

     gem install  activesupport

     gem install  activerecord

     gem install  actionpack

     gem install  actionmailer

     gem install  rake

     gem install  rails    

成功安装之后检查命令

    rails –v

image

证明安装成功

4、创建web应用

      在命令行下输入 rails helloworld,比如当前的路径是 e:ruby on rails>rails helloworld,便会在e:ruby on rails下创建一个helloworld文件夹。

image

如果需要指定路径可以rails c://test,具体可以看官方api:http://api.rubyonrails.org/

5、在当前目录(helloworld)下,运行 ruby scriptserver 启动服务,关于webrick服务器更多的信息可以访问 http://www.webrick.org/

image

6、浏览器中输入http://localhost:3000/,如果看到以下页面,说明ok

image

7、写一个helloworld的web程序,ruby scriptgenerate controller helloworld命令

image

  然后找到hello_world_controller.rb

 
    class helloworldcontroller < applicationcontroller    def index         render:text=>"hello world"   end    end

输入以下代码,保存

如果未启动服务需要重启第五步操作。

在浏览器中打开http://localhost:3000/hello_world,就会看见结果,但我这里出现一个错误:

image

在网上看到一个解决方法:

这是由于没有装sqlite3数据库教程,http://files.cnblogs.com/geek007/sqlite3.rar 这里下载,

然后解压到ruby的bin目录:d:rubybin,命令行执行:gem install "d:program filesruby187binsqlite3-ruby-1.2.3-mswin32.gem"

image

安装成功后,按照第五步重启服务器,在浏览器中访问

http://localhost:3000/hello_world

image

本文来源:http://www.gdgbn.com/jiaocheng/28943/