Ruby实践—HelloWorld

开发环境

OS:WindowsXP

Ruby: Ruby1.9.1

Rails: Rails2.3.5

IDE: RubyMine2.0.1

1、创建Rails工程

Ruby实践—HelloWorld

2、修改 /config/database.yml

自动创建的工程中默认数据库连接的是sqlite,如果没有安装此数据库,需要修改该配置(本例中使用的是mysql)

3、创建Controller

在app/controller中创建say_controller.rb

Ruby实践—HelloWorld

创建完成后,在控制台信息中将显示此过程创建的一系列文件

C:\Ruby19\bin\ruby.exe -e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift) E:/Ruby/HelloWorld/script/generate controller -s say
exists app/controllers/
exists app/helpers/
create app/views/say
exists test/functional/
create test/unit/helpers/
create app/controllers/say_controller.rb
create test/functional/say_controller_test.rb
create app/helpers/say_helper.rb
create test/unit/helpers/say_helper_test.rb

Process finished with exit code 0

4、修改say_controller.rb

将内容修改如下:

5、创建hello.rhtml.erb

在app/views/say 目录下创建hello.rhtml.erb

Ruby实践—HelloWorld

修改其中的内容如下:

6、修改routes.rb

修改config/routes.rb,设置新的映射规则

启动服务Rails服务器,运行 http://localhost:3000/say/Hello (注意匹配大小写)

Ruby实践—HelloWorld

你可能感兴趣的:(mysql,sqlite,OS,Ruby,Rails)