aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/command_line.md
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2012-09-28 23:47:15 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2012-09-28 23:47:15 +0530
commitb8aa3923af388dfbaf7524a83f3ee2f1f59cc36a (patch)
treec42b10af1171e0c6e9d644cdefca2dd170f174a9 /guides/source/command_line.md
parent955a72c692a4298d238cc2e6353b9874099203f1 (diff)
downloadrails-b8aa3923af388dfbaf7524a83f3ee2f1f59cc36a.tar.gz
rails-b8aa3923af388dfbaf7524a83f3ee2f1f59cc36a.tar.bz2
rails-b8aa3923af388dfbaf7524a83f3ee2f1f59cc36a.zip
revise commandline guide [ci skip]
Diffstat (limited to 'guides/source/command_line.md')
-rw-r--r--guides/source/command_line.md18
1 files changed, 6 insertions, 12 deletions
diff --git a/guides/source/command_line.md b/guides/source/command_line.md
index b66b30a117..e7ecdc51d8 100644
--- a/guides/source/command_line.md
+++ b/guides/source/command_line.md
@@ -480,15 +480,9 @@ The `tmp:` namespaced tasks will help you clear the `Rails.root/tmp` directory:
* `rake secret` will give you a pseudo-random key to use for your session secret.
* `rake time:zones:all` lists all the timezones Rails knows about.
-### Writing Rake Tasks
+### Custom Rake Tasks
-If you have (or want to write) any automation scripts outside your app (data import, checks, etc), you can make them as rake tasks. It's easy.
-
-INFO: [Complete guide about how to write tasks](http://rake.rubyforge.org/files/doc/rakefile_rdoc.html) is available in the official documentation.
-
-Tasks should be placed in `Rails.root/lib/tasks` and should have a `.rake` extension.
-
-Each task should be defined in next format (dependencies are optional):
+Custom rake tasks have a `.rake` extension and are placed in `Rails.root/lib/tasks`.
```ruby
desc "I am short, but comprehensive description for my cool task"
@@ -498,7 +492,7 @@ task :task_name => [:prerequisite_task, :another_task_we_depend_on] do
end
```
-If you need to pass parameters, you can use next format (both arguments and dependencies are optional):
+To pass arguments to your custom rake task:
```ruby
task :task_name, [:arg_1] => [:pre_1, :pre_2] do |t, args|
@@ -509,7 +503,7 @@ end
You can group tasks by placing them in namespaces:
```ruby
-namespace :do
+namespace :db
desc "This task does nothing"
task :nothing do
# Seriously, nothing
@@ -517,12 +511,12 @@ namespace :do
end
```
-You can see your tasks to be listed by `rake -T` command. And, according to the examples above, you can invoke them as follows:
+Invocation of the tasks will look like:
```bash
rake task_name
rake "task_name[value 1]" # entire argument string should be quoted
-rake do:nothing
+rake db:nothing
```
NOTE: If your need to interact with your application models, perform database queries and so on, your task should depend on the `environment` task, which will load your application code.