1.必須安裝Ruby和Rails成功過
2.開始建立第一個WEB程式,命令如下:
c:/>md rubydev
c:/>cd rubydev
c:/rubydev>rails -d mysql first
值得注意的是,建立程式的原始命令應該為:rails first,但如果按照此命令,就會報錯:
“no such file to load -- sqlite3”。
估計是沒有找到sqlite的資料庫,開啟database.yml,發現Rails已經自動給我加上了 sqlite的配置了。而且,還給出了安裝sqlite驅動的命令。但是,我不想使用sqlite。上網查了查,原來Rails升級到2.0.2之後使用 sqlite3作為預設的資料庫。
3.修改config下面的檔案database.yml,將裡面的所有的database設定為空白。不修改的話將會報錯,另外在pwd中填寫你自己的mysql的密碼。---------------非常重要。。。
4.輸入:ruby script/server,在瀏覽器中輸入http://localhost:3000,會顯示主介面
5.好的,既然是MVC模式,那麼就先來建立控制器
命令列如下:ruby script/generate controller hello
這就產生了一個控制器,相對應的就是C:/rubydev/first/app/controllers的hello_controller.rb
建立一個動作,也就是修改C:/rubydev/first/app/controllers的hello_controller.rb檔案內容如下:
class HelloController < ApplicationController
def there
end
end
第七步:在/app/views/hello目錄下面編寫there.rhtml,內容如下:
<html>
<head>
<title>Using Rudy on Rails</title>
</head>
<h1>Welcome to Ruby on Rails</h1>
this is your first ruby on rails applictation
<br>
<br>
Using this applicaiton,you've been introduced to controllers,actions,and views.
<br>
<br>
Not bad for a first example!
</body>
</html>
第八步:輸入:ruby script/server,瀏覽器輸入http://localhost:3000/hello/there,介面出來了。。 表示成功
注意:當使用mysql時,會提示no such file to load -- mysql ,解決方案如下:
在win32上ruby串連MySQl(轉)
1.首先安裝好MySql 最新的應該是5.0
2.為Ruby安裝mysql驅動,安裝方法請自己網上查詢,可以直接使用gem install mysql遠程安裝(一定要安裝mysql驅動成功)
2.在D:/ruby/lib/ruby/gems/1.8/gems/mysql-2.8.1-x86-mswin32/lib/1.8下找到mysql_api.so