ruby on rails helloworld

环境:

    ubuntu13.10,aptana stdio3

流程:

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

程序

一、建立controller

    命令:rails generate controller say

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

二、建立view,供controller提取返回给请求

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

往其中添加代码:

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

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

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

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

四、在浏览器中浏览

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

参考:

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

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

你可能感兴趣的:(helloworld,Ruby)