Skip to content

Commit b8aa392

Browse files
committed
revise commandline guide [ci skip]
1 parent 955a72c commit b8aa392

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

guides/source/command_line.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -480,15 +480,9 @@ The `tmp:` namespaced tasks will help you clear the `Rails.root/tmp` directory:
480480
* `rake secret` will give you a pseudo-random key to use for your session secret.
481481
* `rake time:zones:all` lists all the timezones Rails knows about.
482482
483-
### Writing Rake Tasks
483+
### Custom Rake Tasks
484484
485-
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.
486-
487-
INFO: [Complete guide about how to write tasks](http://rake.rubyforge.org/files/doc/rakefile_rdoc.html) is available in the official documentation.
488-
489-
Tasks should be placed in `Rails.root/lib/tasks` and should have a `.rake` extension.
490-
491-
Each task should be defined in next format (dependencies are optional):
485+
Custom rake tasks have a `.rake` extension and are placed in `Rails.root/lib/tasks`.
492486
493487
```ruby
494488
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
498492
end
499493
```
500494
501-
If you need to pass parameters, you can use next format (both arguments and dependencies are optional):
495+
To pass arguments to your custom rake task:
502496
503497
```ruby
504498
task :task_name, [:arg_1] => [:pre_1, :pre_2] do |t, args|
@@ -509,20 +503,20 @@ end
509503
You can group tasks by placing them in namespaces:
510504
511505
```ruby
512-
namespace :do
506+
namespace :db
513507
desc "This task does nothing"
514508
task :nothing do
515509
# Seriously, nothing
516510
end
517511
end
518512
```
519513
520-
You can see your tasks to be listed by `rake -T` command. And, according to the examples above, you can invoke them as follows:
514+
Invocation of the tasks will look like:
521515
522516
```bash
523517
rake task_name
524518
rake "task_name[value 1]" # entire argument string should be quoted
525-
rake do:nothing
519+
rake db:nothing
526520
```
527521
528522
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.

0 commit comments

Comments
 (0)