`
clark1231
  • 浏览: 255253 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

A Guide to the Rails Command Line

阅读更多

rails

1.new and server

With just three commands we whipped up a Rails server listening on port 3000

rails new commandsapp
cd commandsapp
rails server(rails s)

rails server -e production -p 4000

rails server –help

2.generate

rails generate controller NAME [action action] [options]
eg: rails generate controller Say hello goodbye

rails generate model NAME [field:type field:type] [options]
eg: rails generate model post title:string body:text published:boolean

rails generate scaffold HighScore user:references game:string score:integer
rails generate migration add_quantity_to_production quantity:integer

the common data definition tasks detail

add_column
add_index
change_column
change_table
create_table
drop_table
remove_column
remove_index
rename_column

3.other

rails console(rails c)
rails dbconsole(rails db)
rails plugin

rails runner(rails r)
eg: rails runner "Model.long_running_method"

rails destroy(rails d)
eg: rails generate model Oops
    rails destroy model Oops

Rake

rake --tasks(rake -T)  #show a list of Rake tasks

1.about

rake about    #About your application's environment

2.assets

rake assets:clean          # Remove compiled assets
rake assets:precompile     # Compile all the assets named in config.assets.precompile

3.db

rake db:create             # Create the database from config/database.yml for the current Rails.env
rake db:create:all         # Create all dbs

rake db:drop               # Drops the database for the current Rails.env (use db:drop:all to drop all databases)
rake db:fixtures:load      # Load fixtures into the current environment's database.

rake db:migrate            # Migrate the database (options: VERSION=x, VERBOSE=false).
rake db:migrate:status     # Display status of migrations
rake db:migrate:down version=..........
rake db:migrate redo

rake db:perf:all           # recreate table and test data
rake db:perf:perf          # populate test data
rake db:perf:prepare       # recreate table structure for populating data

rake db:populate           # recreate table and test data
rake db:populate:all       # recreate table and test data
rake db:populate:populate  # populate test data
rake db:populate:prepare   # recreate table structure for populating data

rake db:rollback           # Rolls the schema back to the previous version (specify steps w/ STEP=n) eg:rake db:rollback STEP=3.
rake db:schema:dump        # Create a db/schema.rb file that can be portably used against any DB supported by AR
rake db:schema:load        # Load a schema.rb file into the database

rake db:seed               # Load the seed data from db/seeds.rb
rake db:setup              # Create the database, load the schema, and initialize with the seed data
rake db:reset
rake db:structure:dump     # Dump the database structure to db/structure.sql. Specify another file with DB_STRUCTURE=db/my_structure.sql
rake db:version            # Retrieves the current schema version number

4.routes

rake routes                # list all of your defined routes

5.tmp

rake tmp:cache:clear       # clears tmp/cache.
rake tmp:sessions:clear    # clears tmp/sessions.
rake tmp:sockets:clear     # clears tmp/sockets.
rake tmp:clear             # clears all the three: cache, sessions and sockets.

6.spec

rake spec                  # Run all specs in spec directory (excluding plugin specs)
rake spec:controllers      # Run the code examples in spec/controllers
rake spec:helpers          # Run the code examples in spec/helpers
rake spec:lib              # Run the code examples in spec/lib
rake spec:mailers          # Run the code examples in spec/mailers
rake spec:models           # Run the code examples in spec/models
rake spec:rcov             # Run all specs with rcov
rake spec:requests         # Run the code examples in spec/requests
rake spec:routing          # Run the code examples in spec/routing
rake spec:views            # Run the code examples in spec/views

7.log

rake log:clear             # Truncates all *.log files in log/ to zero bytes

8.stats

rake stats                 # show the detail of code(lines,classes,methods...)

detail

gem

gem -v                                                # gem版本
gem update                                            # 更新所有包
gem update --system                                   # 更新RubyGems软件

gem install rake                                      # 安装rake,从本地或远程服务器
gem install rake --remote                             # 安装rake,从远程服务器
gem install watir -v(或者--version) 1.6.2              # 指定安装版本的
gem uninstall rake                                    # 卸载rake包

gem list                                              # 列出所有安装的gem
gem list d                                            # 列出本地以d打头的包
gem query -n '[0-9]' --local                          # 查找本地含有数字的包
gem search log --both                                 # 从本地和远程服务器上查找含有log字符串的包
gem search log --remoter                              # 只从远程服务器上查找含有log字符串的包
gem search -r log                                     # 只从远程服务器上查找含有log字符串的包

gem help                                              # 提醒式的帮助
gem help install                                      # 列出install命令 帮助
gem help examples                                     # 列出gem命令使用一些例子

gem build rake.gemspec                                # 把rake.gemspec编译成rake.gem
gem check -v pkg/rake-0.4.0.gem                       # 检测rake是否有效
gem cleanup                                           # 清除所有包旧版本,保留最新版本
gem contents rake                                     # 显示rake包中所包含的文件
gem dependency rails -v 0.10.1                        # 列出与rails相互依赖的包
gem environment                                       # 查看gem的环境
gem list | cut -d" " -f1 | xargs gem uninstall -aIx   # 删除所有安装的gem

 

你可以去我另一个blog上看,这里没有重新调整格式:http://caok.github.com/blog/2012/05/13/a-guide-to-the-rails-command-line/

分享到:
评论

相关推荐

    Ruby on Rails Guides_ A Guide to Testing Rails Applications.pdf

    综上所述,《Ruby on Rails Guides_ A Guide to Testing Rails Applications.pdf》是一个全面的资源,无论你是Rails新手还是资深开发者,都能从中学习到如何为Rails应用编写高质量的测试。从理论到实践,从单元测试...

    A Guide to Testing the Rails.pdf

    标题:"A Guide to Testing the Rails.pdf" 描述:"A Guide to Testing the Rails" 此份文档旨在深入探讨Ruby on Rails框架下的测试策略,为开发者提供一份详尽的测试指南。文档涵盖了从理论基础到实际应用的全...

    The Rails 5 Way-Leanpub(2017).pdf

    The more confident reader might be able to get started in Rails using just this book, extensive online resources, and his wits, but there are other publications that are more introductory in nature ...

    The Rails3 Way, 2nd Edition

    The Rails™ 3 Way is the only comprehensive, authoritative guide to delivering production-quality code with Rails 3. Pioneering Rails expert Obie Fernandez and a team of leading experts illuminate ...

    Ruby on Rails Guides_ A Guide to Active Record Associations.pdf

    Ruby on Rails Guides_ A Guide to Active Record Associations.pdf

    The Rails 4 Way

    ### 关于《The Rails 4 Way》的知识点总结 #### 标题:The Rails 4 Way 这本书主要讲述了Ruby on Rails 4版本的核心特性和最佳实践。Ruby on Rails(简称Rails)是一个用Ruby语言编写的开源全栈Web应用框架。本书...

    the rails way

    《The Rails Way》一书由Obie Fernandez撰写,属于Addison-Wesley Professional Ruby系列,该系列致力于为读者提供实用、面向人且深入的信息,帮助他们利用Ruby平台创建动态技术解决方案。这一系列书籍的创立基于一...

    Beginning Ruby on Rails

    You'll learn to build Rails applications, connect to databases, perform necessary testing, and put the whole thing together to create real-world applications such as shopping carts and online ...

    Agile Web Development with Rails 4

    You concentrate on creating the application, and Rails takes care of the details., Tens of thousands of developers have used this award-winning book to learn Rails. It’s a broad, far-reaching ...

    rails 5 test prescriptions build a healthy codebase

    Test the component parts of a Rails application, including the back-end model logic and the front-end display logic. With Rails examples, use testing to enable your code to respond better to future ...

    THE RAILS 4 WAY, 3RD EDITION

    Book Details Publisher: Addison-Wesley Professional By: Obie Fernandez ISBN-10: 0321944275 ISBN-13: 978-0321944276 Year: June 8, 2014 Pages: 912 Language: English File size: 4 MB ...

    The rails4 way

    ### 关于《The Rails 4 Way》的知识点总结 #### 书籍概述 《The Rails 4 Way》是一本深入探讨Ruby on Rails 4框架特性的专业书籍,由Obie Fernandez、Kevin Faustino和Vitaly Kushner共同撰写。本书旨在为开发者...

Global site tag (gtag.js) - Google Analytics