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

相關文章
相關標籤/搜索