-
Notifications
You must be signed in to change notification settings - Fork 0
/
rails_rake_notes.txt
66 lines (50 loc) · 1.43 KB
/
rails_rake_notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
========================================================================
Command Line Basics
------------------------------------------------------------------------
# https://guides.rubyonrails.org/command_line.html
# All commands can run with -h or --help to list more information.
bin/rails console
bin/rails server
bin/rails test
bin/rails generate
bin/rails db:migrate
bin/rails db:create
bin/rails routes
bin/rails dbconsole
rails new app_name
> bin/rails generate task feeds list
lib/tasks/feeds.rake:
namespace :feeds do
desc "TODO"
task list: :environment do
u = User.first
puts "hello #{u.email}"
end
end
> find it: rails -T
> run it: rails feeds:list --> hello [email protected]
* :environment loads the whole environment and allows you to use models classes .. etc
- To use arguments
namespace :feeds do
desc "TODO"
task :list, [:v1] => [:environment] do |task, args|
u = User.first
puts "hello #{u.email} #{task} #{args.v1}"
end
end
> rails "feeds:list[jj]" --> hello [email protected] feeds:list jj
- Making chain of tasks
namespace :feeds do
desc "TODO"
task :list, [:v1] => [:list2] do |task, args|
u = User.first
puts "hello #{u.email} #{task} #{args.v1}"
end
desc "TODO 2"
task :list2 => :environment do |task|
u = User.last
puts "hello #{u.email}"
end
end
> rails "feeds:list[jj]" --> hello [email protected]
hello [email protected] feeds:list jj