`

详解rails命令行

阅读更多
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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics