- Published
- Author
- Nived HariSystem Analyst
Rake tasks in Rails let you run custom scripts from the command line.
You can define your own tasks inside the
How to Create a Custom Rake Task
1. Create a new
Define the task inside the file:
Run the task from the terminal:
Use
#CU6U0R822 #rake
You can define your own tasks inside the
lib/tasks directory.How to Create a Custom Rake Task
1. Create a new
.rake file in lib/tasks/ Code
touch lib/tasks/custom_tasks.rakeDefine the task inside the file:
Code
namespace :custom do
desc "Say hello from a custom rake task"
task :hello do
puts "Hello from custom Rake task!"
end
endRun the task from the terminal:
Code
bin/rake custom:helloUse
:environment if your task interacts with the database or models#CU6U0R822 #rake