今天有人問到怎麼清 log ,結果我一直記得 Rails 的 Rakefile 可以幫你 log,不過還是忘記怎麼打了,查了一下發現只要 rake log:clear 即可。
在 Rails 裡面,預設了很多 rake 指令可以幫你輕鬆達成許多任務。這裡列出所有的 Rails Rake Task List。基本上,要叫出 Task List 只要在 Rails 資料夾下面打 rake --task ,或是 rake -T ,他就會自動幫我們叫出 Rails 下面所有的 Rake Task List。
在 Rails 裡面,預設了很多 rake 指令可以幫你輕鬆達成許多任務。這裡列出所有的 Rails Rake Task List。基本上,要叫出 Task List 只要在 Rails 資料夾下面打 rake --task ,或是 rake -T ,他就會自動幫我們叫出 Rails 下面所有的 Rake Task List。
DB 處理方面的 Task
- rake db:fixtures:load # Load fixtures into the current environment's database. Load specific fixtures using FIXTURES=x,y
- rake db:migrate
# Migrate the database through scripts in db/migrate. Target specific version with VERSION=x
使用 Database 的 migrate 功能,他會把 db/migrate 裡面寫的 script 寫入到 DB 裡面。 - 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:sessions:clear
# Clear the sessions table
假設你的 Session 是利用 CGI::Session::ActiveRecordStore 存在 DB 裡面的時候,這個指令可以清理裡面Session 的 Table - rake db:sessions:create
# Creates a sessions table for use with CGI::Session::ActiveRecordStore - rake db:structure:dump # Dump the database structure to a SQL file
- rake db:test:clone # Recreate the test database from the current environment's database schema
- rake db:test:clone_structure # Recreate the test databases from the development structure
- rake db:test:prepare # Prepare the test database and load the schema
- rake db:test:purge # Empty the test database
自動建立 RDoc
- rake doc:app # Build the app HTML Files
- rake doc:clobber_app # Remove rdoc products
- rake doc:clobber_plugins # Remove plugin documentation
- rake doc:clobber_rails # Remove rdoc products
- rake doc:plugins # Generate documation for all installed plugins
- rake doc:rails # Build the rails HTML Files
- rake doc:reapp # Force a rebuild of the RDOC files
- rake doc:rerails # Force a rebuild of the RDOC files
清理 log file
- rake log:clear # Truncates all *.log files in log/ to zero bytes
Rails 版本 Freeze 跟 Update
- rake rails:freeze:edge # Lock to latest Edge Rails or a specific revision with REVISION=X (ex: REVISION=4021) or a tag with TAG=Y (ex: TAG=rel_1-1-0)
- 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 configs, scripts and public/javascripts from Rails
- rake rails:update:configs # Update boot/config.rb from your current rails install
- rake rails:update:javascripts # Update your javascripts from your current rails install
- rake rails:update:scripts # Add new scripts to the application script/ directory
報導現在的 code state
- rake stats # Report code statistics (KLOCs, etc) from the application
Unit Testing 方面
- 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
清理 tmp/ 底下的暫存檔
- rake tmp:cache:clear # Clears all files and directories in tmp/cache
- rake tmp:clear # Clear session, cache, and socket files from tmp/
- rake tmp:create # Creates tmp directories for sessions, cache, and sockets
- rake tmp:sessions:clear # Clears all files in tmp/sessions
- rake tmp:sockets:clear # Clears all files in tmp/sockets