http://blog.58share.com/?cat=7
詳解rails指令行
1.rails 指令
(1). rails new 建立項目
1
# 會生成一個基于資料庫類型為sqlite3的項目
2
$ rails new demo
3
create README.rdoc
4
create Rakefile
5
create config.ru
6
create .gitignore
7
create Gemfile
8
.....
9
10
# 會生成一個基于mysql的項目
11
$ rails new demo -d=mysql
12
13
# 具體的每個參數的意思請參考
14
$ rails new --help
15
16
# 常用配置
17
$ rails new demo -d=mysql -TfJ # 跳過javascript,test
(2). rails server 啟動項目
1
#rails s (rails server 簡寫)
2
$ rails s # development模式啟動
3
$ rails s -e production # production模式啟動
4
$ rails s -p 3001 # 以3001端口啟動伺服器
5
$ rails s -u # debugger調試使用
6
$ rails s -P=tmp/pids/server.pid # 以pid模式啟動
7
8
$ rails s --help
(3). rails generate
1
# 用法: rails generate GENERATOR [args] [options]
2
$ rails g controller Demos index --no-test-framework # 建立一個控制器
3
$ rails g model demo # 建立一個model
4
$ rails g scaffold HighScore game:string score:integer # 建立一個腳手架
5
$ rails g migration add_column_to_table
6
7
$ rails g --help
(4). rails console
1
$ rails c # development模式
2
3
# 使用會復原資料, 加了參數--sandbox後
4
$ rails console --sandbox
5
6
$ rails c production # production模式
(5). rails console / rails db 進入資料庫
(6). rails runner / rails r
1
$ rails r 'Model.long_running_method' # 執行程式
2
$ rails r 'Model.long_running_method' -e production # production 模式
(7). rails destroy / rails d 清除資料
1
$ rails g model user # 建立model
2
$ rails d model user # 删除model
2. rake 指令
1
$ rake -T # 檢視所有的rake指令
檢視源代碼列印幫助
1
$ rake about # 檢視項目相關資訊
2
$ rake assets:precompile # 編譯壓縮css,js,png圖檔, 放到public/assets目錄下
3
$ rake assets:clean # 清除編譯的檔案
4
5
$ rake middleware # 檢視rack #####
6
$ rake db:create # 建立資料庫
7
$ rake db:drop # 删除資料庫
8
$ rake db:migrate # 資料遷移 rake db:migrate RAILS_ENV=production
9
$ rake db:rollback # 復原資料遷移
10
$ rake db:migrate:down VERSION=xxxxx # 復原指定的遷移号
11
12
$ rake routes # 檢視路由
13
14
$ rake tmp:cache:clear # clears tmp/cache.
15
$ rake tmp:sessions:clear # clears tmp/sessions.
16
$ rake tmp:sockets:clear # clears tmp/sockets.
17
$ rake tmp:clear # clears all the three: cache, sessions and sockets.
18
19
$ rake db:version # 檢視目前資料遷移的版本
20
$ rake db:seed # 載入資料從 db/seeds.rb中
21
22
$ rake log:clear # 清空日志 log/*.log