总结各种Ruby on Rails命令

开发 开发工具
Ruby on Rails命令各种各样,掌握起来还是比较麻烦的。为此我们就帮助大家总结这些常用命令,方便大家以后查询。

Ruby on Rails的熟练应用可以帮助我们轻松实现代码编写,让编程变得更加轻松。为了更进一步了解Ruby on Rails,我们需要先从Ruby on Rails命令开始了解。#t#

51CTO推荐专题:Ruby on Rails开发教程

Ruby on Rails命令之创建一个Rails应用程序
$ rails app_name
可选项:
-d, database=xxx 指定安装一个数据库(mysql oracle postgresql sqlite2 sqlite3 ), 默认情况下是数据库
-r, ruby-path= 指定Ruby的安装路径,如果没有指定,scrīpts使用env去找Ruby
-f, freeze (冻结)freezes Rails在vendor/rails目录

Ruby on Rails命令之API Documentation
$ gem_server
启动一个WEBrick服务器。这时候你可以通过Http://localhost:8808/ 打开浏览器去查看rails API文档

Ruby on Rails命令之Rake
rake db:fixtures:load
# 载入fixtures到当前环境的数据库
# 载入指定的fixtures使用FIXTURES=x,y
rake db:migrate
# 迁移数据库通过在db/migrate目录下的脚本.可以指定版本号通过VERSION=x
rake db:schema:dump
# 创建一个db/schema.rb文件,通过AR能过够支持任何数据库去使用
rake db:schema:load
# 再入一个schema.rb文件进数据库
rake db:sessions:clear
# 清空sessions表
rake db:sessions:create
# 用CGI::Session::ActiveRecordStore创建一个sessions表为用户
rake db:structure:dump
# 导出数据库结构为一个SQL文件
rake db:test:clone
# 重新创建一个测试数据库从当前环境数据库中
rake db:test:clone_structure
# 重新创建测试数据库从开发模式数据库
rake db:test:prepare
# 准备测试数据库并在入schema
rake db:test:purge
# 清空测试数据库
rake doc:app
# 创建HTML文件的API Documentation
rake doc:clobber_app
# 删除Documentation
rake doc:clobber_plugins
# 删除 plugin Documentation
rake doc:clobber_rails
# 删除Documentation
rake doc:plugins
# 产生Documation为所有安装的plugins
rake doc:rails
# 创建HTML文件的API Documentation
rake doc:reapp
# 强制重新创建HTML文件的API Documentation
rake doc:rerails
# 强制重新创建HTML文件的API Documentation
rake log:clear
# 清空目录log/下的所有日志文件
rake rails:freeze:edge
# Lock this application to latest Edge Rails. Lock a specific revision with REVISION=X
rake rails:freeze:gems
# Lock this application to the current gems (by unpacking them into vendor/rails)
rake rails:unfreeze
# Unlock this application from freeze of gems or edge and return to a fluid use of system gems
rake rails:update
# Update both scrīpts and public/javascrīpts from Rails
rake rails:update:javascrīpts
# Update your javascrīpts from your current rails install
rake rails:update:scrīpts
# Add new scrīpts to the application scrīpt/ directory
rake stats
# Report code statistics (KLOCs, etc) from the application
rake test
# Test all units and functionals
rake test:functionals
# Run tests for functionalsdb:test:prepare
rake test:integration
# Run tests for integrationdb:test:prepare
rake test:plugins
# Run tests for pluginsenvironment
rake test:recent
# Run tests for recentdb:test:prepare
rake test:uncommitted
# Run tests for uncommitteddb:test:prepare
rake test:units
# Run tests for unitsdb:test:prepare
rake tmp:cache:clear
# 清空tmp/cache目录下的所有文件
rake tmp:clear
# 清空session, cache, 和socket文件从tmp/目录
rake tmp:create
# 为sessions, cache, and sockets创建tmp/目录
rake tmp:sessions:clear
# 清空所有在tmp/sessions目录下的文件
rake tmp:sockets:clear
# 清空所有在tmp/sessions 目录下的ruby_sess.* 文件

Ruby on Rails命令之scrīpts
scrīpt/about
# 输出当前环境信息
scrīpt/breakpointer
# 启动断点server
scrīpt/console
# 启动交换式的Rails控制台
scrīpt/destroy
# 删除通过generators创建的文件
scrīpt/generate
# -> generators
scrīpt/plugin
# -> Plugins
scrīpt/runner
# 执行一个任务在rails上下文中
scrīpt/server
# 启动开发模式服务器http://localhost:3000
//以下几个不知道怎么去使用
scrīpt/performance/profiler
scrīpt/performance/benchmarker
scrīpt/process/reaper
scrīpt/process/spawner

Ruby on Rails命令之Generators
ruby scrīpt/generate model ModelName
ruby scrīpt/generate controller ListController show edit
ruby scrīpt/generate scaffold ModelName ControllerName
ruby scrīpt/generate migration AddNewTable
ruby scrīpt/generate plugin PluginName
ruby scrīpt/generate mailer Notification lost_password signup
ruby scrīpt/generate web_service ServiceName api_one api_two
ruby scrīpt/generate integration_test TestName
ruby scrīpt/generate session_migration

可选项:
-p, --pretend Run but do not make any changes.
-f, --force Overwrite files that already exist.
-s, --skip Skip files that already exist.
-q, --quiet Suppress normal output.
-t, --backtrace Debugging: show backtrace on errors.
-h, --help Show this help message.
-c, --svn Modify files with subversion. (Note: svn must be in path)

Ruby on Rails命令之Plugins
scrīpt/plugin discover
# discover plugin repositories
scrīpt/plugin list
# list all available plugins
scrīpt/plugin install where
# install the a

责任编辑:曹凯 来源: 博客园
相关推荐

2009-12-16 17:24:26

Ruby on Rai

2009-08-27 10:21:22

Ruby on Rai

2009-08-06 09:13:36

Ruby on Rai

2015-10-14 17:27:18

性能

2009-12-14 15:30:43

安装Ruby on R

2009-12-16 16:37:59

Ruby on Rai

2015-10-10 11:00:05

RubyRails性能

2009-12-23 16:39:55

WPF命令

2010-09-25 14:39:29

Bruce Tate

2009-12-16 17:37:31

Ruby on Rai

2009-12-16 15:41:10

Ruby on Rai

2009-12-17 17:37:42

Ruby on Rai

2009-12-16 15:23:33

Ruby on rai

2009-12-16 16:24:00

Ruby on Rai

2010-07-12 09:22:05

RubyRuby on rai

2013-03-28 12:42:02

RubyRails

2009-09-29 17:04:29

2010-10-09 08:58:03

NginxRuby on Rai

2009-03-30 14:40:45

Ruby on RaiRails更新Rails

2011-08-31 17:41:07

Ruby
点赞
收藏

51CTO技术栈公众号