ruby on rails helloworld

环境:

    ubuntu13.10,aptana stdio3 html

流程:

      用户发送一个请求Rails, Rails接受请求(RUL)后进行解析找到合适的Control, 再调用Control中合适方法进行处理, 返回一个特定视图View. 将结果显示给最终用户. ubuntu

程序

1、创建controller

    命令:rails generate controller say 浏览器

    say为controller的名称,执行完以后能够在controller文件夹中看见say_controller.rb文件。文件中自动定义了SayController类继承类ApplicationController。类中定义的方法是为框架中的一个Action。详细看前面流程。 框架

2、创建view,供controller提取返回给请求

    创建了controller以后,rails会自动在view中生成controller同名的文件夹,在该演示中view文件夹下生成了say文件夹。在文件夹下添加与Action对应的view。添加hello.html.erb(hello与方法hello是同名的). spa

往其中添加代码: .net

<html>
	<head>
		<title>hello,world</title>
	</head>
	<body>
		<h1>hello,world</h1>>
	</body>
</html>

3、在routes.rb文件中添加路径信息

    打开config/routes.rb文件,添加 code

    get "say/hello" => "say#hello" htm

4、在浏览器中浏览

    在浏览器地址栏中输入 http://localhost:3000/say/hello blog

参考:

    http://blog.csdn.net/oec2003/article/details/2288069 继承

    http://ihower.tw/rails3/firststep.html