note for rails guide

来源:互联网 发布:玉米 番薯 知乎 编辑:程序博客网 时间:2024/06/11 09:21

http://guides.ruby.tw/rails3/getting_started.html

$rails new blog #创建一个rails项目

$ cd blog #

$ bundle install  

#Rails 使用 Bundler gem 來管理所有你應用程式會依存的 gems 到 vendor 目錄。到目前為止,我們根據預設不需要特殊的 gem,我們只需要執行以下指令就可以準備好了


資料庫需要一個設定檔是 config/database.yml


$ rake db:create #讓 Rails 建立空的資料庫了


$ rails server #Ctrl C to exit


http://localhost:3000     #运行,看到public/index.html,静态页面。


$ rails generate controller home index #创建ctl,名字为home,并且有一个方法名为index #无modle


app/views/home/index.html.erb#修改其内容


$ cp public/index.htmlpublic/index.html.bak

$ rm public/index.html

$ vim config/routes.rb

mod like this ------

Blog::Application.routes.drawdo

 # You can have the root of your site routed with "root"

# just remember to delete public/index.html.

root :to =>"home#index"


$ rails generate scaffold Post name:string title:string content:text


$ rake db:migrate


mod  app/view/home/index like this

<%= link_to "My Blog", posts_path %>

這個 link_to 函式是 Rails 內建的 view helpers (View 的輔助函式)。它會建立一個文字超連結,連到文章列表。







note for rails guide





aaaaaa





aaaa




原创粉丝点击