Rails 3 Script/ 改版
1.环境
- # ruby -v
- ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
- # rails -v
- Rails 3.0.7
- gem -v
- 1.3.7
- # gem list
-
- *** LOCAL GEMS ***
- abstract (1.0.0)
- actionmailer (3.0.7)
- actionpack (3.0.7)
- activemodel (3.0.7)
- activerecord (3.0.7)
- activeresource (3.0.7)
- activesupport (3.0.7)
- addressable (2.2.4)
- arel (2.0.10)
- bson (1.3.1)
- bson_ext (1.3.1)
- builder (2.1.2)
- bundler (1.0.13)
- capistrano (2.6.0)
- capybara (0.4.1.2)
- celerity (0.8.9)
- childprocess (0.1.9)
- configuration (1.2.0)
- cucumber (0.10.2)
- cucumber-rails (0.4.1)
- culerity (0.2.15)
- database_cleaner (0.6.7)
- diff-lcs (1.1.2)
- erubis (2.6.6)
- factory_girl (2.0.0.beta2, 1.3.3)
- factory_girl_rails (1.1.beta1, 1.0.1)
- faraday (0.6.1)
- fcgi (0.8.8)
- ffi (1.0.9)
- gherkin (2.3.8)
- highline (1.6.2)
- i18n (0.5.0)
- JSON (1.5.1)
- json_pure (1.5.1)
- launchy (0.4.0)
- login_generator (1.2.2)
- mail (2.2.19)
- mime-types (1.16)
- minitest (1.6.0)
- monGo (1.3.1)
- mongoid (2.0.2)
- mongoid-rspec (1.4.2)
- multi_json (1.0.2)
- multi_xml (0.2.2)
- multipart-post (1.1.1)
- Mysql2 (0.2.6)
- net-ldap (0.2.2)
- net-scp (1.0.4)
- net-sftp (2.0.5)
- net-ssh (2.1.4)
- net-ssh-gateway (1.1.0)
- nokogiri (1.4.4)
- oa-basic (0.2.6)
- oa-core (0.2.6)
- oa-enterprise (0.2.6)
- oa-more (0.2.6)
- oa-oauth (0.2.6)
- oa-openid (0.2.6)
- oauth (0.4.4)
- oauth2 (0.4.1)
- omniauth (0.2.6)
- polyglot (0.3.1)
- pyu-ruby-sasl (0.0.3.2)
- rack (1.2.2)
- rack-mount (0.6.14)
- rack-openid (1.3.1)
- rack-test (0.5.7)
- rails (3.0.7)
- railties (3.0.7)
- rake (0.9.0, 0.8.7)
- rdoc (2.5.8)
- rest-client (1.6.1)
- rspec (2.6.0)
- rspec-core (2.6.2)
- rspec-expectations (2.6.0)
- rspec-mocks (2.6.0)
- rspec-rails (2.6.0)
- ruby-fcgi (0.8.9)
- ruby-openid (2.1.8)
- ruby-openid-apps-discovery (1.2.0)
- rubyntlm (0.1.1)
- rubyzip (0.9.4)
- selenium-WEBdriver (0.2.0)
- sqlite3 (1.3.3)
- sqlite3-ruby (1.3.3)
- term-ansicolor (1.0.5)
- thor (0.14.6)
- treetop (1.4.9)
- tzinfo (0.3.27)
- xpath (0.1.4)
2.尝试指令
相信如果之前用过 2.* rails 的人都知道. 我们习惯用 ./script/generate [xxxx] 或者 ./script/* [xxxx].
现在这些在rails 3.*都没有了?
- # rails new lala
- create
- ... ...
- create script
- create script/rails
- ... ...
研究才发现,新版rails,在一次封装分类了.
- Usage: rails COMMAND [ARGS]
-
- The most common rails commands are:
- generate Generate new code (short-cut alias: "g")
- console Start the Rails console (short-cut alias: "c")
- server Start the Rails server (short-cut alias: "s")
- dbconsole Start a console for the database specified in config/database.yml
- (short-cut alias: "db")
- new Create a new Rails application. "rails new my_app" creates a
- new application called MyApp in "./my_app"
-
- In addition to those, there are:
- application Generate the Rails application code
- destroy Undo code generated with "generate"
- benchmarker See how fast a piece of code runs
- profiler Get profile infORMation from a piece of code
- plugin Install a plugin
- runner Run a piece of code in the application environment
-
- All commands can be run with -h for more information.
比如我们之前常用的,./script/generate controller [xxxx] 现改为:
- # ./script/rails generate controller account
- create app/controllers/account_controller.rb
- invoke erb
- create app/views/account
- invoke test_unit
- create test/functional/account_controller_test.rb
- invoke helper
- create app/helpers/account_helper.rb
- invoke test_unit
- create test/unit/helpers/account_helper_test.rb
同时加了几个选项:
- Usage: rails generate GENERATOR [args] [options]
- General options:
- -h, [--help] # Print generator's options and usage
- -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 status output
以此类推。。。
相关文章