2016年3月1日 星期二

Ruby on Rails Note 學習筆記


首先

https://www.ruby-lang.org/zh_tw/

下載  ==>  下載安裝  ==>  RubyInstaller(Windows)  ==> RailsInstaller安裝包    繞呀繞

找到這個快速安裝工具
http://railsinstaller.org/en

看到 Windows Ruby 2.2 按下,下載
內容包括(Packages included are)
Ruby 2.2.4
Rails 4.2
Bundler
Git
Sqlite
TinyTDS
SQL Server Support
DevKit

安裝完成後,開始選單裡面,有了 RailsInstaller 目錄
裡面有
Command Prompt with Ruby and Rails
Interactive Ruby
Git Bash
RubyGems  Documentation Server

我看了Eduonix Learning Solutions的Video
他說要用  Command Prompt with Ruby and Rails   去執行  rails new project_name (專案名)
來建立新的網頁專案,但是卻回應:  系統找不到指定路徑。

絕望之際,發現可以透過  Git Bash視窗來執行上述命令。
第二步要啟動 Server (像是Apache那樣) 來在瀏覽器上觀看自己的專案,
也是必須要透過 Git Bash 在自己的專案中的 資料架中  執行  rails server

執行成功後,就可以在 Chrome裡面輸入  localhost:3000 看到自己的網頁了。

怎麼跟Eduonix Learning Solutions的Video教的不太一樣,好險我自己研究出來了。成功。

建立新的網頁:
開始製造自己的網頁  在自己的專案目錄下   輸入指定 rails generate home index 建立網頁

在  /app/views  與 /app/controllers 中都可以看到相關的檔案被建立起來
產生以下檔案
/app/controllers/home_controller.rb
/app/views/home/index.html.erb

改變首頁路徑(routes):
進入/config/routes.rb   發現新的寫法與舊的寫法不同   關於root如何轉到新建立的頁面
舊寫法  root '' :to =>   'home#index'
新寫法   root 'home#index'  (不過新舊寫法都可以正常運作。)

估計是精簡化的結果

教學中顯示的預設 localhost:3000 的首頁是有一個有/public/index.html 但是我卻看不到.....


Rails 強迫 MVC架構?  強迫Git ? 似乎是..........


rails new XXX -d mysql  (新建一個專案  以MySQL作為資料庫)
然後要在 /config/database.yml  中  增加密碼   並且把databases給註解掉  因為還沒有建立資料庫

然後開啟 rails server 就可以正常顯示預設page

rails generate controller demo index


##################################################################

git add -A
git status
git commit -m   ' ........'


BitBucket (Push file 上傳本機的 git)
git commit -m ' ~  ~ ~'
git push -u origin master


Deployment Option: Heroku


#####################################################

安裝PostgreSQL
http://www.postgresql.org/download/

heroku雲端
http://blog.eddie.com.tw/2012/01/06/heroku-the-best-cloud-platform-on-ruby-language/

教學
Ruby on Rails Tutorial Learn Web Development with Rails Michael Hartl
https://www.railstutorial.org/book





沒有留言:

張貼留言