Rails RVM bundle gem 常用命令 - tianlu1677/tianlu1677.github.io GitHub Wiki
rails常用命令
rails --help
generate Generate new code (short-cut alias: "g")
`例如: rails g controller user name:string email:string `
console Start the Rails console (short-cut alias: "c")
` 例如: rails c 或者 rails c --sandbox(这个会运行一个沙箱环境)`
server Start the Rails server (short-cut alias: "s")
`例如: rails s -e production -p 3006 在生产环境中 在3006端口启动rails服务`
dbconsole Start a console for the database specified in config/database.yml
(short-cut alias: "db")
`例如: rails db 进入到数据库,可以运行sql语句`
new Create a new Rails application. "rails new my_app" creates a
new application called MyApp in "./my_app"
`例如: rails new myapp --skip-bundle 在生成新的项目时,跳过bundle,更多内容 rails new --help`
Rvm常用命令
rvm --help
`安装curl -L https://get.rvm.io | bash -s stable`
rvm list
rvm list known
rvm use 2.1.1 --default `切换Ruby的版本并且设置为默认`
rvm install 2.1.1
rvm reinstall 2.1.1
rvm uninstall 2.1.1
bundle 常用命令
bundle - Ruby Dependency Management
bundle install `Install the gems specified by the Gemfile or Gemfile.lock`
bundle update `Update dependencies to their latest versions`
bundle exec *** `执行某段脚本`
bundle list | active `显示gem名字中带 active的 gem`,只显示在某个项目中的gem
gem常用命令
gem --help
gem install gem_name
gem uninstall gem_name
gem list --local
gem install gem_name --version 0.3.1 `安装特定版本的gem`
rake 常用命令
rake --task `显示所有命令`
rake about `任务输出以下信息:Ruby、RubyGems、Rails 的版本号,Rails 使用的组件,程序所在的文件夹,Rails 当前所处的环境名,程序使用的数据库适配器,数据库模式版本号。`
`对rake db 详细一点说`
rake db:migrate `执行还没执行的迁移中的 change 或 up 方法,rake db:migrate 按照迁移文件名中时间戳顺序执行迁移。`
rake db:migrate VERSION=20080906120000
rake db:rollback
rake db:rollback STEP=3
rake db:migrate:redo STEP=3
rake db:setup
rake db:reset
rake db:migrate RAILS_ENV=test
如何从零开始建立一个gem
最简单的编写一个gem
bundle gem test_gem
cd test_gem
vim test_gem.gemspec `修改里面的TODO`
vim lib/test_gem.rb `添加自己的代码`
gem build test_gem.gemspec
gem install test_gem.0.0.1.gem
详细内容参见: